note 62791 added to language.oop5.basic

From: Date: Thu, 09 Mar 2006 19:11:03 +0000
Subject: note 62791 added to language.oop5.basic
Groups: php.notes 
Request: Send a blank email to php-notes+get-105157@lists.php.net to get a copy of this message
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! ?> ---- Server IP: 66.163.161.117 Probable Submitter: 207.171.180.101 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.basic.php Edit -- http://master.php.net/note/edit/62791 Del: integrated -- http://master.php.net/note/delete/62791/integrated Del: useless -- http://master.php.net/note/delete/62791/useless Del: bad code -- http://master.php.net/note/delete/62791/bad+code Del: spam -- http://master.php.net/note/delete/62791/spam Del: non-english -- http://master.php.net/note/delete/62791/non-english Del: in docs -- http://master.php.net/note/delete/62791/in+docs Del: other reasons-- http://master.php.net/note/delete/62791 Reject -- http://master.php.net/note/reject/62791 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#105157) next »