Bug #79462 [PATCH]: method_exists and property_exists incoherent behavior
| From: | cmb@php.net | Date: | Thu, 09 Apr 2020 09:20:48 +0000 |
| Subject: | Bug #79462 [PATCH]: method_exists and property_exists incoherent behavior | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-226503@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79462&edit=1
ID: 79462
Patch added by: cmb@php.net
Reported by: lucasfbustamante at gmail dot com
Summary: method_exists and property_exists incoherent
behavior
Status: Assigned
Type: Bug
Package: Class/Object related
Operating System: Linux
PHP Version: 7.4.4
Assigned To: girgias
Block user comment: N
Private report: N
New Comment:
The following pull request has been associated:
Patch Name: Fix #79462: method_exists and property_exists incoherent behavior
On GitHub: https://github.com/php/php-src/pull/5362
Patch: https://github.com/php/php-src/pull/5362.patch
Previous Comments:
------------------------------------------------------------------------
[2020-04-09 08:04:52] nikic@php.net
We probably should change method_exists() to throw TypeError, just like property_exists() does now.
------------------------------------------------------------------------
[2020-04-09 01:02:26] lucasfbustamante at gmail dot com
Description:
------------
This output speaks more than a thousand words: https://3v4l.org/oRnjq
The first argument of method_exists just returns false if it's not an object, while it's
twin method, property_exists, shows a warning if the exact same thing happens.
This behavior is inconsistent and prone to cause confusion amongst users.
I'd like to suggest that
property_exists just returns false if the first argument
is not an object, like method_exists does.
Best regards,
Lucas
Test script:
---------------
<?php
var_dump( method_exists(null, 'foo') );
var_dump( property_exists(null, 'foo') );
Expected result:
----------------
property_exists returns false if the first argument is not an object
Actual result:
--------------
property_exists throws a warning if the first argument is not an object
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79462&edit=1