Edit report at https://bugs.php.net/bug.php?id=63841&edit=1
ID: 63841 Updated by: krak...@php.net Reported by: paxcoder+phpnet at gmail dot com Summary: Mind the constructor return value -Status: Open +Status: Not a bug Type: Feature/Change Request Package: Class/Object related PHP Version: Irrelevant Block user comment: N Private report: N New Comment: The job of a constructor is not to return a value but to construct an object, this is implicit in the implementation and associated keywords. For example, one cannot call $var=stdClass::__construct(), because they are not, and cannot be static functions. Making such a check is completely unnecessary and costly. Not a bug. Previous Comments: ------------------------------------------------------------------------ [2012-12-23 16:20:35] paxcoder+phpnet at gmail dot com Description: ------------ As-is, returning values in the constructor has no effect, and the class instance is returned instead. Either allow for explicitly returned values to supersede the object, or warn about trying to return a value from a constructor. Test script: --------------- <?php error_reporting(E_ALL|E_STRICT); class C { function __construct() { return NULL; } } $c = new C; print_r($c); ?> Expected result: ---------------- Either a warning at line 10, or $c set to NULL Actual result: -------------- No warning, and $c set to a C Object ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=63841&edit=1