Can a object be instanced as null ? (php) -
i don't understand behavior in php (since 5.4 ? )
class test { function __construct() { return null ; } } ; $a = new test() ; if($a) { echo "i printing this. why printing ??" ; }
$a should equal null passes test if()...
in case (if arguments invalid exemple) possible null object when using 'new' ?
constructors not return anything. after ctor has run, object has been created. return null
ignored.
edit: if possible return null in ctor when failed bad practice.
throw exception
clear message instead.
help page: http://www.php.net/manual/en/language.exceptions.php
Comments
Post a Comment