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

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

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