php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #56665 Can't add mixed-case method
Submitted: 2005-11-20 10:27 UTC Modified: 2013-02-23 19:13 UTC
From: jobapply at nextmail dot ru Assigned: pollita (profile)
Status: Closed Package: runkit (PECL)
PHP Version: 5_1 CVS-2005-11-20 OS: FreeBSD 5
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jobapply at nextmail dot ru
New email:
PHP Version: OS:

 

 [2005-11-20 10:27 UTC] jobapply at nextmail dot ru
Description:
------------
Can't add a method with mixed-case naming.
Like 'Test', 'getA' ...


Reproduce code:
---------------

class Example  {

}


runkit_method_add(
'Example',
'Test',
'',
'return 5;',
RUNKIT_ACC_PUBLIC
);

$e = new Example();
echo $e->Test();

Expected result:
----------------
5

Actual result:
--------------
PHP Fatal error:  Call to undefined method Example::Test() in /var/site/setter/reproduce2.php on line 18

Fatal error: Call to undefined method Example::Test() in /var/site/setter/reproduce2.php on line 18


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-02-05 23:40 UTC] daniel dot oconnor at gmail dot com
Is this issue with PHP_RUNKIT_ADD_MAGIC_METHOD and the use of strcmp vs how class + method names are stored internally in PHP?

IE, using stricmp instead of strcmp would correct this issue?

Line #257
http://cvs.php.net/viewcvs.cgi/pecl/runkit/php_runkit.h?annotate=1.23
 [2009-07-21 20:42 UTC] pear dot neufeind at speedpartner dot de
@Daniel: strcmp is fine. Function table always has lower-case entries.

Entries into the function_table (zend_hash_add, ...) need to be performed with lowercase functionnames. Calls to get_class_methods will still show the mixed-case-variant since that's stored together with the function (separate of the function_table).


Testcase for direct as well as indirect calls to function with mixed-case as well as listing function names:
<?
class Foo {
 function a() {
  self::barB();
}
 }
runkit_method_add("Foo","barB",'',"return;");
print_r(get_class_methods("Foo"));
Foo::barB();
Foo::a();


Tested fix for the problem:
--- runkit_methods.c.orig       2007-12-27 22:16:05.000000000 +0100
+++ runkit_methods.c    2009-07-22 02:32:02.000000000 +0200
@@ -344,6 +344,7 @@

        func.common.fn_flags |= ZEND_ACC_ALLOW_STATIC;
 #endif
+       php_strtolower(methodname, methodname_len);

        zend_hash_apply_with_arguments(EG(class_table), (apply_func_args_t)php_runkit_update_children_methods, 5, ancestor_class, ce, &func, methodname,
 methodname_len);
 [2013-02-23 19:13 UTC] pollita@php.net
-Status: Verified +Status: Closed -Assigned To: +Assigned To: pollita
 [2013-02-23 19:13 UTC] pollita@php.net
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat May 08 19:01:24 2021 UTC