Req #69594 [Opn]: magic isNull method for objects (like toString)

From: Date: Thu, 07 May 2015 19:21:25 +0000
Subject: Req #69594 [Opn]: magic isNull method for objects (like toString)
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-192564@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69594&edit=1 ID: 69594 User updated by: di3 at gmx dot net Reported by: di3 at gmx dot net Summary: magic isNull method for objects (like toString) Status: Open Type: Feature/Change Request Package: Class/Object related PHP Version: Irrelevant Block user comment: N Private report: N New Comment: i agree its related to te other requests you found. the boolean representation wod work too. i' m just missing a empty representation for a object usecase is nullobject design returning a magic null object with nested method calls class nullObject { public function __isNull() { return true; } public function __call($a,$b) { return $this } } class mapper { public function find($x) { ...some thing else return new nullObject; } } ... if ($mapper->find(..)->getUser()->getGroup() === null .. so i want to call null as object or call a object which represent null. if i call a method on null there should be a result null for that call too same as int bool array why is there only toString Previous Comments: ------------------------------------------------------------------------ [2015-05-07 17:01:13] cmb@php.net The request is related to request #43909. Somewhat related is also the Nullsafe Calls RFC: <https://wiki.php.net/rfc/nullsafe_calls>. I wonder when this magic method shall be triggered. Only when used with isset, empty and is_null, or more generally in boolean context. If the latter, it is also related to request #69486. ------------------------------------------------------------------------ [2015-05-07 13:28:31] di3 at gmx dot net Description: ------------ add a magic null method for objects (like __toString) to check if object is_null or empty. public function __isNull() return true or false many using null objects to get a secure returnvalue would be nice a object representate null is comparable. same for empty ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=69594&edit=1

« previous php.bugs (#192564) next »