php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #69594 magic isNull method for objects (like toString)
Submitted: 2015-05-07 13:28 UTC Modified: 2015-05-07 19:21 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: di3 at gmx dot net Assigned:
Status: Open Package: Class/Object related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2015-05-07 13:28 UTC] 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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-05-07 17:01 UTC] 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 19:21 UTC] di3 at gmx dot net
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
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun Sep 15 18:01:27 2019 UTC