note 103857 deleted from function.isset by danbrown

From: Date: Fri, 06 May 2011 23:12:05 +0000
Subject: note 103857 deleted from function.isset by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-179513@lists.php.net to get a copy of this message
Note Submitter: langpavel at phpskelet dot org ---- I wrote this class, but after some little thinking I decide to reject this code as very bad idea. There is no way to override is_null() and (bool) implicit conversion behavior in conditions. It seems that only good way is via array_key_exists or ($ === null) comparison. <?php // /** // * This class represents null value that behave as true value for isset() // * WARNING // * UNFORTUNATELY cast to bool in if() expression, is_null(), RETURNS TRUE; // * empty() RETURNS FALSE // */ // final class DBNull // implements HtmlValue, SQLValue // { // public static $value; // public static $text = ''; // public static $html_text = '<span class="DBNull">null</span>'; // public static $sql_text = 'NULL'; // //public static $html_text = '<span class="DBNull" style="color:#00f">null</span>'; // // private function __construct() { } // // public static function value() // { // if(DBNull::$value === null) // DBNull::$value = new DBNull(); // return DBNull::$value; // } // // public function __toString() { return DBNull::$text; } // public function toHtml() { return DBNull::$html_text; } // public function toSQL() { return DBNull::$sql_text; } // // function __get($name) { throw new Exception('Cannot get property of DBNull'); } // function __set($name, $value) { throw new Exception('Cannot set property on DBNull'); } // function __unset($name) { throw new Exception('Cannot unset property on DBNull'); } // function __isset($name) { return false; } // } // // $GLOBALS['DBNull'] = DBNull::$value = DBNull::value(); // // function DBNull() { return DBNull::$value; }

« previous php.notes (#179513) next »