note 62791 deleted from language.oop5.basic by bjori
| From: | bjori@php.net | Date: | Wed, 26 Apr 2006 16:48:20 +0000 |
| Subject: | note 62791 deleted from language.oop5.basic by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-109769@lists.php.net to get a copy of this message | ||
Note Submitter: jcaplan at amazon dot com
----
Overcome a defect in PHP's "operator new" syntax which forces us to name single-use
object instances, as pointed out by tobias_demuth at web dot de:
We are forced to write
<?php
$phpForcedMeToNameThis = new MyClass(p1, ..., pn);
$phpForcedMeToNameThis->myMethod(q1, ..., qm);
?>
instead of
<?php
( new MyClass(p1, ..., pn) )->myMethod(q1, ..., qm); // rejected!
?>
A simple workaround is to define the identity function globally:
<?php
public function I( $x ) { return $x; }
?>
Now you only have to add one character to the example above:
<?php
I( new MyClass(p1, ..., pn) )->myMethod(q1, ..., qm); // ok!
?>