note 103857 added to function.isset

From: Date: Fri, 06 May 2011 23:02:20 +0000
Subject: note 103857 added to function.isset
Groups: php.notes 
Request: Send a blank email to php-notes+get-179512@lists.php.net to get a copy of this message
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; } ---- Server IP: 69.147.83.197 Probable Submitter: 62.240.163.46 ---- Manual Page -- http://www.php.net/manual/en/function.isset.php Edit -- https://master.php.net/note/edit/103857 Del: integrated -- https://master.php.net/note/delete/103857/integrated Del: useless -- https://master.php.net/note/delete/103857/useless Del: bad code -- https://master.php.net/note/delete/103857/bad+code Del: spam -- https://master.php.net/note/delete/103857/spam Del: non-english -- https://master.php.net/note/delete/103857/non-english Del: in docs -- https://master.php.net/note/delete/103857/in+docs Del: other reasons-- https://master.php.net/note/delete/103857 Reject -- https://master.php.net/note/reject/103857 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#179512) next »