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

Popular posts from this blog

javascript - How to name a jQuery function to make a browser's back button work? -

python - Django-easy-pdf: xhtml2pdf reporting reportlab 2.2+ is required, but 3.0 installed -

collision detection - C++ library for mesh to mesh intersection: what is available? -