php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #44857 no property_exists() equivalent for magic properties
Submitted: 2008-04-28 18:05 UTC Modified: 2021-08-03 14:45 UTC
Votes:14
Avg. Score:4.5 ± 0.8
Reproduced:13 of 13 (100.0%)
Same Version:4 (30.8%)
Same OS:5 (38.5%)
From: mike at silverorange dot com Assigned: cmb (profile)
Status: Wont fix Package: Class/Object related
PHP Version: 5.2.5 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mike at silverorange dot com
New email:
PHP Version: OS:

 

 [2008-04-28 18:05 UTC] mike at silverorange dot com
Description:
------------
There is currently no way to determine if a magic __get() property exists.

The __isset() function should use 'isset(null) == false' semantics so it cannot be used to reliably check if a magic property exists.

I propose a new magic method __property_exists($name) or __propertyExists($name) be created that hooks into the property_exists() function. It would return true iff __get($name) returns any value.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-08-03 14:45 UTC] cmb@php.net
-Status: Open +Status: Wont fix -Package: Feature/Change Request +Package: Class/Object related -Assigned To: +Assigned To: cmb
 [2021-08-03 14:45 UTC] cmb@php.net
> It would return true iff __get($name) returns any value.

That would require to actually call __get(), what appears to be a
bad idea.  Superseeding magic getters/setters with property
accessors[1] or similar appears to be the better option.  Thus,
I'm closing as WONTFIX.

If you still feel that there should be a way to detect magic
getters/setters, please pursue the RFC process[2].

[1] <https://wiki.php.net/rfc/property_accessors>
[2] <https://wiki.php.net/rfc/howto>
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jan 05 05:01:28 2025 UTC