#35728 [Bgs->Opn]: constructors with a return by reference cause a notice to be thrown
| From: | t dot isler at bbn dot de | Date: | Mon, 19 Dec 2005 13:29:46 +0000 |
| Subject: | #35728 [Bgs->Opn]: constructors with a return by reference cause a notice to be thrown | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-90658@lists.php.net to get a copy of this message | ||
ID: 35728
User updated by: t dot isler at bbn dot de
Reported By: t dot isler at bbn dot de
-Status: Bogus
+Status: Open
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. 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.
Previous Comments:
------------------------------------------------------------------------
[2005-12-19 00:32:22] tony2001@php.net
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