On 12-08-12 08:32 AM, Reto Kaiser wrote:

So I have this strange situation where I assign a classvariable a
value, but when I read the value it is NULL.

The class has one variable declared:
class A {
         private $_cookies;

That is a private instance variable NOT a class variable.

To declare a class variable you would do the following:


class A
    private static $_cookies;


In a method of this class I assign this classvariable plus an
undeclared classvariable and a local variable the value 1:
$this->_cookies = 1;
$this->_cookies2 = 1;
$cookies3 = 1;

When I now read the values of those variables, the classvariables are
NULL while the local variable is 1:
$logEntry .= 'cookies: ' . var_export($this->_cookies, true) . PHP_EOL;
$logEntry .= 'cookies2: ' . var_export($this->_cookies2, true) . PHP_EOL;
$logEntry .= 'cookies3: ' . var_export($cookies3, true) . PHP_EOL;
cookies: NULL
cookies2: NULL
cookies3: 1

But when reading the whole object, the classvariables are 1:
$logEntry .= var_export($this, true) . PHP_EOL;
    '_cookies' => 1,
    '_cookies2' => 1,

This happens periodically on a busy webserver. It seems that when it
happens, all classvariables cannot be read anymore (return NULL).
After restarting Apache it does not happen anymore, just to happen
again after some minutes.

The system is current Debian Squeeze:
Linux: linux-image-2.6.32-5-amd64
Apache: apache2-mpm-prefork 2.2.16-6+squeeze7
PHP: PHP 5.3.3-7+squeeze13 with Suhosin-Patch (cli) (built: Jun 10
2012 07:31:32)
php -m: 
php -i: 

Does anyone have an idea what could cause this, or how to further debug?

I can't really speak to your specific problem (unless you're using two different instances of the class), just thought I'd clear up the difference between class variables and instance variables.

E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to