ID: 35728 Updated by: [EMAIL PROTECTED] Reported By: t dot isler at bbn dot de -Status: Open +Status: Bogus Bug Type: Scripting Engine problem PHP Version: 5.1.1 New Comment:
>Even if I remove the assignments by reference it does not > change the problem. Yes it does. >Next to fact that I do not see the sense of your code example That's exactly what I wanted to demonstrate. There is no point in returning by reference from constructor, since it doesn't return anything at all. Previous Comments: ------------------------------------------------------------------------ [2005-12-19 14:29:45] t dot isler at bbn dot de Even if I remove the assignments by reference it does not change the problem. Next to fact that I do not see the sense of your code example unless you wish to imply that constructors in PHP do not differ from regular functions. As far as OOP is concerned a constructor has an implicit return ($this) and languages such as C++ or Java will throw an error, if a constructor includes an explicit return. ------------------------------------------------------------------------ [2005-12-19 00:32:22] [EMAIL PROTECTED] Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php That's exactly what you get with this: <?php function &foo() {} $test = & foo(); ?> And this is expected behaviour (because your code is obviously wrong). Also, if you set error_reporting to E_ALL | E_STRICT, you'll see even more error messages telling you about your code. ------------------------------------------------------------------------ [2005-12-19 00:18:50] t dot isler at bbn dot de Description: ------------ I don't know wether you want to consider the following a bug, but as far as my understanding of oop is concerned, the behavior of php 4.4 and 5.1 is "unusual" when comes to constructors with a return by reference. Reproduce code: --------------- <?php class firstObject { function & __construct() {} } class secondObject { function & __construct() {return $this;} } $firstObject =& new firstObject(); $secondObject =& new secondObject(); ?> Expected result: ---------------- The first constructor should pass without a problem, the second should throw an error. Actual result: -------------- The first constructor throws a notice, the second passes without any problem. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=35728&edit=1