|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-05-17 08:59 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 17:00:01 2025 UTC |
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!