|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2013-10-22 11:55 UTC] daverandom@php.net
[2013-10-22 12:02 UTC] bwoebi@php.net
-Status: Open
+Status: Duplicate
[2013-10-22 12:02 UTC] bwoebi@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 21:00:01 2025 UTC |
Description: ------------ Either new \MyClass($foo->getBar()) is used or new $class($foo->getBar()) is used. If the instanciated class has no constructor explicitly defined or inherited, $foo->getBar() will never be invoked. This prevent any side-effect to be run and can produce very unexpected behaviour. This should either be fixed so the arguments are ALWAYS evaluated, or documented as such. CF example belows Test script: --------------- <?php class foo { public $i = 0; function createANewBar() { ++$i; return null; } } class no_construct { } class a_construct { public function __construct() { } } $myFoo = new foo; echo $myFoo->i.PHP_EOL; $class = 'no_construct'; $object = new $class($myFoo->createANewBar()); echo $myFoo->i.PHP_EOL; $object = new no_construct($myFoo->createANewBar()); echo $myFoo->i.PHP_EOL; $class = 'a_construct'; $object = new $class($myFoo->createANewBar()); echo $myFoo->i.PHP_EOL; $object = new a_construct($myFoo->createANewBar()); echo $myFoo->i.PHP_EOL; Expected result: ---------------- 0 1 2 3 4 Actual result: -------------- 0 0 0 1 2