Bug #79462 [Opn]: method_exists and property_exists incoherent behavior

From: Date: Thu, 09 Apr 2020 08:04:52 +0000
Subject: Bug #79462 [Opn]: method_exists and property_exists incoherent behavior
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-226501@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 Updated by: nikic@php.net Reported by: lucasfbustamante at gmail dot com Summary: method_exists and property_exists incoherent behavior Status: Open Type: Bug Package: Class/Object related Operating System: Linux PHP Version: 7.4.4 -Assigned To: +Assigned To: girgias Block user comment: N Private report: N New Comment: We probably should change method_exists() to throw TypeError, just like property_exists() does now. Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#226501) next »