OOP'deki Değişken değişkenler

0 Cevap php

Hi everyone I'm having a little struggle on this one and would appreciate some help.

PHP değişken değişkenler kolaylıkla böyle tanımlanabilir

$a = "myVar";
$$a = "some Text";
print $myVar; //you get "some Text"

Şimdi, bir OOP ortamında bunu nasıl yapacağız? Ben bu çalıştı:

$a = "myVar";
$myObject->$a = "some Text"; //I must be doing something wrong here
print $myObject->myVar; //because this is not working as expected

Ben de $myObject->{$a} = "some Text" çalıştı ama o da çalışmıyor. Yani bir yere çok yanlış olmalı.

Herhangi bir yardım için teşekkür ederiz!

0 Cevap