Bu mümkün olup olmadığını Im 'merak:
: Ben başarıyla __ set (), bir sınıfın özelliklerine değerlerini ayarlamak için sihirli yöntemi kullandım
class View
{
private $data;
public function __set( $key, $value )
{
$this->data[$key] = $value;
}
}
Yani mümkün kulüpler:
$view = new View();
$view->whatever = 1234;
Ben örneğin bir dizeyi bağlamak istediğinizde sorun gelir. Bu () denir değil (aslında denilen varlık değildir) __ set gibi görünüyor.
$view = new View();
$view->a_string = 'hello everybody'; //Value is set correctly
$view->a_string.= '<br>Bye bye!'; //Nothing happens...
echo $view->a_string;
This outputs "hello everybody". I'm not able to execute __set() in the second assignment. Reading php.net it says that:
__set() is run when writing data to inaccessible properties.
So as *a_string* already exists, __set is not called. My question finally is... how could I achieve that concatenation operation??
Note: Ok... Murphy came and gave me the answer as soon as I posted this...
Cevap (Anladığım kadarıyla), PHP bir __ get () metodu tanımlanmış vermedi * a_string * mevcut ise karar vermek mümkün değildir olmasıdır.
Tanımlama __ get () php * a_string * geçerli değeri bulmak için izin verir, sonra değerini bağlamak için __ set () kullanır.