Bug #52653 [Opn->Csd]: multiple instances made with a singleton

2010-08-20 Thread paulscheltema at gmail dot com
Edit report at http://bugs.php.net/bug.php?id=52653&edit=1

 ID: 52653
 User updated by:paulscheltema at gmail dot com
 Reported by:paulscheltema at gmail dot com
 Summary:multiple instances made with a singleton
-Status: Open
+Status: Closed
 Type:   Bug
 Package:Reproducible crash
 Operating System:   debian
 PHP Version:5.3.3
 Block user comment: N

 New Comment:

Ok great, thanks for the help.


Previous Comments:

[2010-08-20 13:54:31] t-bader at gmx dot net

It's not a bug.



At test::getInstance() the __construct method is invoked which retrieves
the instance from test2. 



The __construct of test2 is invoked and clals test::getInstance(), since
the first call of test::getInstance doesn't finished the constructor
execution self::$instance will never be set and the __construct method
of test is invoked again.



Same with test2:getInstance, so you created an endless loop because the
__construct methods never can finish.


[2010-08-20 11:28:36] paulscheltema at gmail dot com

Description:

Hello, first off, ive been searching but i couldnt find any related
bugreport and im sorry if i wasted your time.



I have 2 classes with both an singleton function in them, an api (test)
and a user (test2) class. The api uses the user data and the user class
uses the api to get its userdata. Hence i load the user class instance
in the api and vice versa.



It works if i use an external class to serve as a singleton storage but
if i use the static $instance it doesnt. 

The singleton function does work when i remove the test2::getInstance()
from class test.

Test script:
---
class test {



private static $instance;

private $test2;



private function __construct() {

$this->test2 = test2::getInstance();

}



public static function getInstance() {

if (!isset(self::$instance)) {

echo 'new test instance';

$c = __CLASS__;

self::$instance = new $c;

}

   return self::$instance;

}



}



class test2 {



private static $instance;

private $test;



private function __construct() {

$this->test = test::getInstance();

}



public static function getInstance() {

if (!isset(self::$instance)) {

echo 'new test2 instance';

$c = __CLASS__;

self::$instance = new $c;

}

   return self::$instance;

}



}



print 'start:';



for ($i = 1; $i < 10; $i++) {



print 'loop: '.$i;

$t = test::getInstance();



}



Expected result:

start:



loop: 1

new test instance

new tes2 instance

loop: 2

loop: 3

loop: 4

loop: 5

loop: 6

loop: 7

loop: 8

loop: 9





Actual result:
--
start:



loop: 1

new test instance

new test2 instance

new test instance

new test2 instance

new test instance

new test2 instance

new test instance

new test2 instance

new test instance

new test2 instance

...

till php runs out of memory






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


[PHP-BUG] Bug #52653 [NEW]: multiple instances made with a singleton

2010-08-20 Thread paulscheltema at gmail dot com
From: 
Operating system: debian
PHP version:  5.3.3
Package:  Reproducible crash
Bug Type: Bug
Bug description:multiple instances made with a singleton

Description:

Hello, first off, ive been searching but i couldnt find any related
bugreport and im sorry if i wasted your time.



I have 2 classes with both an singleton function in them, an api (test) and
a user (test2) class. The api uses the user data and the user class uses
the api to get its userdata. Hence i load the user class instance in the
api and vice versa.



It works if i use an external class to serve as a singleton storage but if
i use the static $instance it doesnt. 

The singleton function does work when i remove the test2::getInstance()
from class test.

Test script:
---
class test {



private static $instance;

private $test2;



private function __construct() {

$this->test2 = test2::getInstance();

}



public static function getInstance() {

if (!isset(self::$instance)) {

echo 'new test instance';

$c = __CLASS__;

self::$instance = new $c;

}

   return self::$instance;

}



}



class test2 {



private static $instance;

private $test;



private function __construct() {

$this->test = test::getInstance();

}



public static function getInstance() {

if (!isset(self::$instance)) {

echo 'new test2 instance';

$c = __CLASS__;

self::$instance = new $c;

}

   return self::$instance;

}



}



print 'start:';



for ($i = 1; $i < 10; $i++) {



print 'loop: '.$i;

$t = test::getInstance();



}



Expected result:

start:



loop: 1

new test instance

new tes2 instance

loop: 2

loop: 3

loop: 4

loop: 5

loop: 6

loop: 7

loop: 8

loop: 9





Actual result:
--
start:



loop: 1

new test instance

new test2 instance

new test instance

new test2 instance

new test instance

new test2 instance

new test instance

new test2 instance

new test instance

new test2 instance

...

till php runs out of memory

-- 
Edit bug report at http://bugs.php.net/bug.php?id=52653&edit=1
-- 
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=52653&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=52653&r=trysnapshot53
Try a snapshot (trunk):  
http://bugs.php.net/fix.php?id=52653&r=trysnapshottrunk
Fixed in SVN:
http://bugs.php.net/fix.php?id=52653&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=52653&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=52653&r=alreadyfixed
Need backtrace:  
http://bugs.php.net/fix.php?id=52653&r=needtrace
Need Reproduce Script:   
http://bugs.php.net/fix.php?id=52653&r=needscript
Try newer version:   
http://bugs.php.net/fix.php?id=52653&r=oldversion
Not developer issue: 
http://bugs.php.net/fix.php?id=52653&r=support
Expected behavior:   
http://bugs.php.net/fix.php?id=52653&r=notwrong
Not enough info: 
http://bugs.php.net/fix.php?id=52653&r=notenoughinfo
Submitted twice: 
http://bugs.php.net/fix.php?id=52653&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=52653&r=globals
PHP 4 support discontinued:  http://bugs.php.net/fix.php?id=52653&r=php4
Daylight Savings:http://bugs.php.net/fix.php?id=52653&r=dst
IIS Stability:   
http://bugs.php.net/fix.php?id=52653&r=isapi
Install GNU Sed: 
http://bugs.php.net/fix.php?id=52653&r=gnused
Floating point limitations:  
http://bugs.php.net/fix.php?id=52653&r=float
No Zend Extensions:  
http://bugs.php.net/fix.php?id=52653&r=nozend
MySQL Configuration Error:   
http://bugs.php.net/fix.php?id=52653&r=mysqlcfg



#44273 [Bgs]: access to private and protected class variables allowed when casting to array

2008-03-11 Thread paulscheltema at gmail dot com
 ID:   44273
 User updated by:  paulscheltema at gmail dot com
 Reported By:  paulscheltema at gmail dot com
 Status:   Bogus
 Bug Type: Scripting Engine problem
 Operating System: Windows XP / Linux Debian
 PHP Version:  5.2.5
 New Comment:

ok, sorry for your time. 

It came on to me as being very strange behaviour.

Its just really annoying you cant hide variables inside classes that
way.

But as the manual says its just about classes, nothing else.

Strange to see then that in newer php versions it is recommended (even
throws an error using strict) to use private/protected/public when
really it doesn't add anything but obstruction.

but again sorry for your time, and ty for the awnser.

regards,
paul


Previous Comments:


[2008-03-11 22:06:32] [EMAIL PROTECTED]

And last but not least, here's an excerpt from the manual
(http://www.php.net/manual/en/language.oop5.visibility.php):

"The visibility of a property or method can be defined by prefixing the
declaration with the keywords: public, protected or private. Public
declared items can be accessed everywhere. Protected limits access to
inherited and parent classes (and to the class that defines the item).
Private limits visibility only to the class that defines the item."



[2008-03-11 22:04:36] [EMAIL PROTECTED]

Maybe this explains it better:


And this will output everything, and it's expected and the correct
behaviour. It's about the properties being isible/not-visible/writable
to other classes. PPP is not meant for providing any security. 
(I admit, I'm bad at explaining things. :)



----

[2008-03-05 14:25:25] paulscheltema at gmail dot com

well, i guess its ok then, its just not what im used to with some other
languages

but i still think its wierd using protected to "protect" the data from
the outside world, but not quite doing so.

i now know storing vital information such as passwords inside class
variables even protected ones, doesnt help much.

so giving another developer access to an api doesnt protect me anymore
either

but if its no bug since changing the data isnt possible that way, so be
it.

and i have to say dont change the point:
first you say its about visibility, 
i explain why it is,
next you say it doesnt matter because you cant change its value



[2008-03-05 14:03:01] [EMAIL PROTECTED]

Yes, but can you _change_ it? (answer: no, not via that array..)

--------

[2008-03-04 13:27:58] paulscheltema at gmail dot com

I think the bug is that I CAN access private / protected class data at
runtime which neglects the whole point of private or protected data
inside classes. It is to be protected!

Why else use private data if you can access it anyway? its useless
then. its just obstruction instead of security. (security in terms of
data integrity)

On the positive side at least i can not change the data.

And to refer to your reaction precisely, lets have two classes A and B
A is instanciated and has a private property x which is set, class B
casts class A to an array and gains access to class A's private property
x. This is not directly about visibility but it allows class B to "view"
class A's private property x.



The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/44273

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



#44273 [Fbk->Opn]: access to private and protected class variables allowed when casting to array

2008-03-05 Thread paulscheltema at gmail dot com
 ID:   44273
 User updated by:  paulscheltema at gmail dot com
 Reported By:  paulscheltema at gmail dot com
-Status:   Feedback
+Status:   Open
 Bug Type: Scripting Engine problem
 Operating System: Windows XP / Linux Debian
 PHP Version:  5.2.5
 New Comment:

well, i guess its ok then, its just not what im used to with some other
languages

but i still think its wierd using protected to "protect" the data from
the outside world, but not quite doing so.

i now know storing vital information such as passwords inside class
variables even protected ones, doesnt help much.

so giving another developer access to an api doesnt protect me anymore
either

but if its no bug since changing the data isnt possible that way, so be
it.

and i have to say dont change the point:
first you say its about visibility, 
i explain why it is,
next you say it doesnt matter because you cant change its value


Previous Comments:


[2008-03-05 14:03:01] [EMAIL PROTECTED]

Yes, but can you _change_ it? (answer: no, not via that array..)



[2008-03-04 13:27:58] paulscheltema at gmail dot com

I think the bug is that I CAN access private / protected class data at
runtime which neglects the whole point of private or protected data
inside classes. It is to be protected!

Why else use private data if you can access it anyway? its useless
then. its just obstruction instead of security. (security in terms of
data integrity)

On the positive side at least i can not change the data.

And to refer to your reaction precisely, lets have two classes A and B
A is instanciated and has a private property x which is set, class B
casts class A to an array and gains access to class A's private property
x. This is not directly about visibility but it allows class B to "view"
class A's private property x.



[2008-03-03 13:41:02] [EMAIL PROTECTED]

Private/protected is about visibility between _classes_ not with a
class cast to an array. So what's the "bug" here?

--------

[2008-02-27 20:49:25] paulscheltema at gmail dot com

Description:

Hello dear developer(s),

When i setup a simple class with a protected/private var,
instanciate the class, and cast the instance to an array
i can access the protected/private var.


Reproduce code:
---
class test {
public $public = 'public';
private $private = 'private';
protected $protected = 'protected';
}

$t = new test;
$a = (array)$t;

print 'public: '.$a['public'];
print 'private: '.$a["\0test\0private"];
print 'protected: '.$a["\0*\0protected"];

Expected result:

Expected:

public: public

Or at most an Error like:
Cannot access private property test::$private
as the value of the private property



Actual result:
--
Result:

public: public
private: private
protected: protected





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



#44273 [Fbk->Opn]: access to private and protected class variables allowed when casting to array

2008-03-04 Thread paulscheltema at gmail dot com
 ID:   44273
 User updated by:  paulscheltema at gmail dot com
 Reported By:  paulscheltema at gmail dot com
-Status:   Feedback
+Status:   Open
 Bug Type: Scripting Engine problem
 Operating System: Windows XP / Linux Debian
 PHP Version:  5.2.5
 New Comment:

I think the bug is that I CAN access private / protected class data at
runtime which neglects the whole point of private or protected data
inside classes. It is to be protected!

Why else use private data if you can access it anyway? its useless
then. its just obstruction instead of security. (security in terms of
data integrity)

On the positive side at least i can not change the data.

And to refer to your reaction precisely, lets have two classes A and B
A is instanciated and has a private property x which is set, class B
casts class A to an array and gains access to class A's private property
x. This is not directly about visibility but it allows class B to "view"
class A's private property x.


Previous Comments:


[2008-03-03 13:41:02] [EMAIL PROTECTED]

Private/protected is about visibility between _classes_ not with a
class cast to an array. So what's the "bug" here?

----

[2008-02-27 20:49:25] paulscheltema at gmail dot com

Description:

Hello dear developer(s),

When i setup a simple class with a protected/private var,
instanciate the class, and cast the instance to an array
i can access the protected/private var.


Reproduce code:
---
class test {
public $public = 'public';
private $private = 'private';
protected $protected = 'protected';
}

$t = new test;
$a = (array)$t;

print 'public: '.$a['public'];
print 'private: '.$a["\0test\0private"];
print 'protected: '.$a["\0*\0protected"];

Expected result:

Expected:

public: public

Or at most an Error like:
Cannot access private property test::$private
as the value of the private property



Actual result:
--
Result:

public: public
private: private
protected: protected





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



#44273 [NEW]: access to private and protected class variables

2008-02-27 Thread paulscheltema at gmail dot com
From: paulscheltema at gmail dot com
Operating system: Windows XP / Linux Debian
PHP version:  5.2.5
PHP Bug Type: Scripting Engine problem
Bug description:  access to private and protected class variables

Description:

Hello dear developer(s),

When i setup a simple class with a protected/private var,
instanciate the class, and cast the instance to an array
i can access the protected/private var.


Reproduce code:
---
class test {
public $public = 'public';
private $private = 'private';
protected $protected = 'protected';
}

$t = new test;
$a = (array)$t;

print 'public: '.$a['public'];
print 'private: '.$a["\0test\0private"];
print 'protected: '.$a["\0*\0protected"];

Expected result:

Expected:

public: public

Or at most an Error like:
Cannot access private property test::$private
as the value of the private property



Actual result:
--
Result:

public: public
private: private
protected: protected

-- 
Edit bug report at http://bugs.php.net/?id=44273&edit=1
-- 
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=44273&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=44273&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=44273&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=44273&r=fixedcvs
Fixed in release: 
http://bugs.php.net/fix.php?id=44273&r=alreadyfixed
Need backtrace:   http://bugs.php.net/fix.php?id=44273&r=needtrace
Need Reproduce Script:http://bugs.php.net/fix.php?id=44273&r=needscript
Try newer version:http://bugs.php.net/fix.php?id=44273&r=oldversion
Not developer issue:  http://bugs.php.net/fix.php?id=44273&r=support
Expected behavior:http://bugs.php.net/fix.php?id=44273&r=notwrong
Not enough info:  
http://bugs.php.net/fix.php?id=44273&r=notenoughinfo
Submitted twice:  
http://bugs.php.net/fix.php?id=44273&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=44273&r=globals
PHP 4 support discontinued:   http://bugs.php.net/fix.php?id=44273&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=44273&r=dst
IIS Stability:http://bugs.php.net/fix.php?id=44273&r=isapi
Install GNU Sed:  http://bugs.php.net/fix.php?id=44273&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=44273&r=float
No Zend Extensions:   http://bugs.php.net/fix.php?id=44273&r=nozend
MySQL Configuration Error:http://bugs.php.net/fix.php?id=44273&r=mysqlcfg