note 120549 deleted from language.oop5.overloading by cmb
| From: | cmb@php.net | Date: | Sun, 29 Dec 2019 10:14:28 +0000 |
| Subject: | note 120549 deleted from language.oop5.overloading by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-213665@lists.php.net to get a copy of this message | ||
Note Submitter: david dot bruchmann at gmail dot com
----
As mentioned by "pogregoire##live.fr" you can attach properties to an object like shown in
his example:
<?php
class Object{
}
$Object = new Object();
$Objet->barbarianProperties = 'boom';
var_dump($Objet); // object(Objet)#1 (1) { ["barbarianProperties"]=> string(7)
"boom" }
?>
This is surly not the right way to use variables and objects but never has any influence on the
object itself, the new property is only associated with the object.
It's not possible to inject closures like this to get protected properties or do any actions:
<?php
class abc {
protected $a = NULL;
protected $b = NULL;
public function __construct($a=NULL, $b=NULL){
$this->a = $a;
$this->b = $b;
}
}
$abc = new abc('uvw','xyz');
var_dump($abc);
$abc->undefined = (function(){
var_dump($this);
return $this->a.', '.$this->b;
});
var_dump($abc);
echo $abc->undefined();
?>
Output:
object(abc)#1 (2) {
["def":protected]=> string(3) "uvw"
["ghi":protected]=> string(3) "xyz"
}
object(abc)#1 (3) {
["def":protected]=> string(3) "uvw"
["ghi":protected]=> string(3) "xyz"
["undefined"]=> object(Closure)#2 (0) { }
}
Fatal error: Call to undefined method abc::undefined() in test.php