#50822 [Opn->Bgs]: Private instance variable visibile for new instance created within an object

From: Date: Fri, 22 Jan 2010 14:38:06 +0000
Subject: #50822 [Opn->Bgs]: Private instance variable visibile for new instance created within an object
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-146870@lists.php.net to get a copy of this message
 ID:               50822
 Updated by:       jani@php.net
 Reported By:      aron at zajlik dot hu
-Status:           Open
+Status:           Bogus
 Bug Type:         Scripting Engine problem
 Operating System: Mac OS X
 PHP Version:      5.3.1
 New Comment:

Ever heard of "singleton" ? Also: 

  http://php.net/manual/en/language.oop5.patterns.php

So yes, this is expected and correct behaviour.


Previous Comments:
------------------------------------------------------------------------

[2010-01-22 12:45:36] aron at zajlik dot hu

Description:
------------
I found a situation which to me seems like unexpected behavior. I 
private variable (as far as I know) should only be accessible within
the 
object itself, and not by the "outside world". Yet this becomes a bit 
confusing once the object is created within an instance of itself. Is 
this a bug or is this expected behavior?

Reproduce code:
---------------
<?
class Test{
	private $variable = "asdf";
	
	static function create_a_test(){
		$tobj = new Test();
		echo $tobj->variable;	// Works! (which it shouldn't?!?)
	}

}

$my_test = new Test();
//echo $my_test->variable;	// Returns Fatal error: Cannot access
private property (which it should!)
$my_test->create_a_test();

?>

Expected result:
----------------
I would expect the above code NOT to return the private variable on
line 
7.

Actual result:
--------------
The private variable can be accessed without a problem.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=50822&edit=1



Thread (4 messages)

« previous php.bugs (#146870) next »