php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33455 is_callable will not handle private/public well from within a class
Submitted: 2005-06-23 22:28 UTC Modified: 2005-06-24 10:09 UTC
From: php at adaniels dot nl Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.0.3 OS: NB
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: php at adaniels dot nl
New email:
PHP Version: OS:

 

 [2005-06-23 22:28 UTC] php at adaniels dot nl
Description:
------------
Function is_callable will not handle private/public well from within a class.


Reproduce code:
---------------
<?php
class X {
	private function getXX($value) {
		return "XX $value";
	}
	
	function testXX() {
		echo (is_callable(array($this, 'getXX')) ? $this->getXX("test") : "Can't call getXX within " . __CLASS__) . "\n";
	}
}

class Y extends X {
	function testXX() {
		echo (is_callable(array($this, 'getXX')) ? $this->getXX("test") : "Can't call getXX within " . __CLASS__) . "\n";
	}
}
	
$x = new X;
echo (is_callable($x, 'getXX') ? $x->getXX("test") : "Can't call getXX outside for " . get_class($x)) . "\n";
$x->testXX();

$y = new y;
echo (is_callable($y, 'getXX') ? $y->getXX("test") : "Can't call getXX outside for " . get_class($y)) . "\n";	
$y->testXX();
?>

Expected result:
----------------
Can't call getXX outside for X
XX test
Can't call getXX outside for Y
Can't call getXX within Y

Actual result:
--------------
Can't call getXX outside for X
XX test
Can't call getXX outside for Y
<br />
<b>Fatal error</b>:  Call to private method X::getXX() from context 'Y' in <b>\\Seabert\webroot\ontwikkeling\quickbuild\test.php</b> on line <b>76</b><br />


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-06-23 23:08 UTC] tony2001@php.net
*ALWAYS* try latest snapshots before reporting a bug.
This was fixed long time ago.

Btw, 5.0.3 is not even the latest version.
 [2005-06-24 01:48 UTC] php at adaniels dot nl
Are you sure? I did not see this bug in the bug reports.

Please do not confuse this bug with Bug #29210  	'Function: is_callable - no support for private and protected classes':
http://bugs.php.net/bug.php?id=29210

Function is_callable does work correctly for private methode's from outside the object, as is done in bug 29210. But is doest not work correctly when using $this within the class as is done in this report.

PS. I use ZendStudio for development. The latest version of ZendStudio is bundeled with PHP 5.0.3. That's why I did not test this under 5.0.4
 [2005-06-24 09:26 UTC] php at adaniels dot nl
Please comment....
 [2005-06-24 10:09 UTC] tony2001@php.net
Yes, I'm sure. And could try latest snapshot and see it yourself.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Mar 13 01:01:31 2025 UTC