php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49220 method_exists check goes wrong when checking for a static function
Submitted: 2009-08-11 09:25 UTC Modified: 2009-08-11 09:33 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: william at 1moment dot nl Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.2.5 OS: Linux
Private report: No CVE-ID: None
 [2009-08-11 09:25 UTC] william at 1moment dot nl
Description:
------------
The method_exists function can have two types of input for the first parameter:

An object instance or a class name.

The documentation (http://us2.php.net/manual/en/function.method-exists.php) has two examples. One for checking static methods and one for checking normal methods. (Based on the type of var for the first parameter).

When i do this in php version 5.2.5 the code below will echo 'testClass has a static function named testFunction'.

When i do this in php version 5.0.4 the code below will echo 
'testClass has not a static function named testFunction'.

I think 5.0.4 is correct behavior.

Thnx!


Reproduce code:
---------------
Class testClass { 
	public function testFunction() {
		return true;
	}
}

if(method_exists('testClass', 'testFunction')) {
	echo 'testClass has a static function named testFunction';
} else {
	echo 'testClass has not a static function named testFunction';
}

Expected result:
----------------
testClass has a static function named testFunction

Actual result:
--------------
testClass has not a static function named testFunction

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-08-11 09:33 UTC] jani@php.net
Both latest PHP 5.2 / 5.3 / HEAD SVN checkouts work just fine and produce your expected behaviour. Time to upgrade..
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Aug 03 12:00:03 2025 UTC