note 59349 deleted from language.oop5.overloading by cmb
| From: | cmb@php.net | Date: | Sun, 18 Dec 2016 10:06:44 +0000 |
| Subject: | note 59349 deleted from language.oop5.overloading by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-208660@lists.php.net to get a copy of this message | ||
Note Submitter: trash80 at gmail dot com
----
Problem: $a->b->c(); when b is not instantiated.
Answer: __get()
<?php
class a
{
function __get($v)
{
$this->$v = new $v;
return $this->$v;
}
}
class b
{
function say($word){
echo $word;
}
}
$a = new a();
$a->b->say('hello world');
// echos 'hello world'
?>