|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2014-01-07 15:25 UTC] robert dot johnson at icap dot com
[2017-07-24 13:57 UTC] jean dot claveau at c277 dot fr
[2021-02-15 13:16 UTC] cmb@php.net
-Status: Open
+Status: Suspended
-Package: Feature/Change Request
+Package: *General Issues
[2021-02-15 13:16 UTC] cmb@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 04:00:02 2025 UTC |
Description: ------------ I've noticed that there is no method for determining if an object is 'false' in the same way that an empty array is equivalent to false. Although the countables interface would be helpful for implementing a feature mimicing array, having a magic method '__isEmpty' would be best for anyone who wants to control the 'emptiness' of an object. This is a suggestion to implement a magic method to determine the true/false value of an object (in the same way a string or int or array can be true or false) Reproduce code: --------------- class Something { var $data; public function __construct($data = null) { if ($data) { $this->data = $data; } } public function __isEmpty() { return isset($this->data); } } $something = new Something(); if (!$something) { echo "huzzah, the magic method works!" } Expected result: ---------------- huzzah, the magic method works!