Re: Reading class variable value always returns NULL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

Thanks for your input Robert and Volmar! I have googled again with
"instance variable" instead of "class variable" - but have not found
any similar reports.

I'm pretty sure those are the same objects. The application usually
runs alright. We only see the instance variables becoming NULL since
about a week.

We had 3 small software upgrade coming from debian since we observe
the problem. We think they cannot be related. Still we have reverted
all of those and still see the problem.
Next step is that we setup a exact copy of the machine. Maybe it is a
hardware problem...

Thanks,
 Reto

On Mon, Aug 13, 2012 at 5:09 PM, Robert Cummings <robert@xxxxxxxxxxxxx> wrote:
> On 12-08-12 08:32 AM, Reto Kaiser wrote:
>>
>> Hi,
>>
>> 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:
>
> <?php
>
> 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;
>> =========
>> A::__set_state(array(
>>     '_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:
>> https://raw.github.com/gist/3331641/2f7e80bd03abfb728b659634d3f4bac0131f4d6a/gistfile1.txt
>> php -i:
>> https://raw.github.com/gist/3331651/bcf6e3654bf391482627505447848de173d0bbab/gistfile1.txt
>>
>> 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.
>
> Cheers,
> Rob.
> --
> 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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux