#23671 [Opn]: Function calls expose private (and undefined) functions in print_r output
| From: | agoossens at olc dot sa dot edu dot au | Date: | Sat, 17 May 2003 14:27:41 +0000 |
| Subject: | #23671 [Opn]: Function calls expose private (and undefined) functions in print_r output | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-39840@lists.php.net to get a copy of this message | ||
ID: 23671
User updated by: agoossens at olc dot sa dot edu dot au
-Summary: Function calls expose private functions in print_r
output
Reported By: agoossens at olc dot sa dot edu dot au
Status: Open
Bug Type: Zend Engine 2 problem
Operating System: Windows XP, SP1
PHP Version: 5CVS-2003-05-17 (dev)
New Comment:
Update: I discovered that the reason the private functions are being
exposed is because functions do not need to be defined to be added to
the output. They simply need to be called at least once anywhere in a
class.
class foo
{
public function sayFoo()
{
$this->doSomeFoo();
}
}
$foo = new foo;
The print_r() output on this will still give
foo Object {
[doSomeFoo]=>
}
Strangely, it seems that here sayFoo() will not appear in the output,
even though it's scope is public!
Previous Comments:
------------------------------------------------------------------------
[2003-05-17 08:59:29] agoossens at olc dot sa dot edu dot au
Greetings all,
When a private function is called from within a class, it is exposed in
the print_r() (or var_dump()) output on it's object.
In order to explain this, consider this code:
class foo
{
private function sayFoo()
{
/* uncomment this line */
//$this->doSomeFoo();
}
private function doSomeFoo()
{
echo "Doing some foo\n";
}
}
$foo = new foo;
// print the structure of $foo
print_r($foo);
// var_dump($foo);
Initially, this will return
foo Object
(
)
Which is correct.
However, if you then uncomment the line in "sayFoo", the print_r will
return the name of the private function as one of the array indexes.
Changing the scope of "sayFoo" does the same thing no matter what scope
you use.
I'm pretty sure this isn't expected behaviour, as that would expose the
private function's existance (even though they still can't be
accessed).
Tested on:
PHP 5.0.0-dev, 200305061830 build, Win32 package.
Cheers
-Adam Goossens
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=23671&edit=1