Hi,

While debugging some memory usage stuff I came across the fact that:

<?php
class foo {
    // $x as a static *class* var
    static $x = "foo";
    static function def() {
        return self::$x;
    }
}

$x1 = foo::def();
$x2 = foo::def();
$x3 = foo::def();
$x4 = foo::def();

xdebug_debug_zval('x4');
?>

will display a refcount of 5 while:

<?php
class foo {
    static function def() {
        // $x as a static *function* var
        static $x = "foo";
        return $x;
    }
}

$x1 = foo::def();
$x2 = foo::def();
$x3 = foo::def();
$x4 = foo::def();

xdebug_debug_zval('x4');
?>

will display a refcount of 1.

Can someone explain me why a real copy is made in the 2nd case?
Is this on purpose?

Regards,
-- 
Patrick Allaert
---
http://code.google.com/p/peclapm/ - Alternative PHP Monitor

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to