note 119890 deleted from language.oop5.magic by cmb
| From: | cmb@php.net | Date: | Sun, 10 Nov 2019 12:37:46 +0000 |
| Subject: | note 119890 deleted from language.oop5.magic by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212984@lists.php.net to get a copy of this message | ||
Note Submitter: ryan dot jentzsch at gmail dot com
----
PHP 7+ solves a problem with __invoke noted about 4 yrs ago:
<?php
class a {
function __construct() { }
function __invoke() { echo("Invoked\n"); }
}
$a = new a();
$a();
// Output: Invoked
class b {
private $x;
function __construct() {
$this->x = new a();
($this->x)(); // Works in PHP 7+
// $this->x(); // Will blow up in your face: undefined method b::x
}
}
$b = new b();
// Output: Invoked