Professional Web Applications Themes

#46169 [NEW]: destruct in wrong order with static object - PHP Bugs

From: luke at cywh dot com Operating system: Linux PHP version: 5.2.6 PHP Bug Type: Scripting Engine problem Bug description: destruct in wrong order with static object Description: ------------ This is related to a bug that was fixed in version 5.2.0, which you can read about here: http://bugs.php.net/bug.php?id=36759 Basically if you were to initiate a class, the destruct order would be incorrect: "C1,C2,C3,D1,D2,D3". This was corrected in 5.2.0 to be "C1,C2,C3,D3,D2,C1". The problem, however, still persists if you create an object inside a static object. Code to recreate this issue is included in this bug report. If you initiate the ...

  1. #1

    Default #46169 [NEW]: destruct in wrong order with static object

    From: luke at cywh dot com
    Operating system: Linux
    PHP version: 5.2.6
    PHP Bug Type: Scripting Engine problem
    Bug description: destruct in wrong order with static object

    Description:
    ------------
    This is related to a bug that was fixed in version 5.2.0, which you
    can read about here:

    http://bugs.php.net/bug.php?id=36759

    Basically if you were to initiate a class, the destruct order would be
    incorrect: "C1,C2,C3,D1,D2,D3". This was corrected in 5.2.0 to be
    "C1,C2,C3,D3,D2,C1".

    The problem, however, still persists if you create an object inside a
    static object. Code to recreate this issue is included in this bug
    report.

    If you initiate the classes without the Registry singleton, it
    destructs properly ($c1 = new class1()...).

    Testing this with 5.1.6, the destruct order is incorrect in both
    situations (as i'd expect). If you unset the objects in reverse order
    as they were created, both work correctly on 5.1.6 and 5.2.6.

    So a work-around for either version is to simply track the objects and
    unset them. But if you don't do this, the destruct order is still
    incorrect if creating your objects through a singleton object.

    Reproduce code:
    ---------------
    class shorten {
    public function __construct() { print 'C:' . get_class($this) . "<br />";
    }
    public function __destruct() { print 'D:' . get_class($this) . "<br />";
    }
    }
    class class1 extends shorten {}
    class class2 extends shorten {}
    class class3 extends shorten {}
    class Registry {
    static private $instance = null;
    private $registered = array();
    static public function instance() {
    if(self::$instance == null) self::$instance = new Registry();
    return self::$instance;
    }
    private function __call($name, $arguments) {
    if( ! isset($this->registered[$name]) ) $this->registered[$name] = new
    $name();
    return $this->registered[$name];
    }
    private function __get($name) {
    if( ! isset($this->registered[$name]) ) $this->registered[$name] = new
    $name();
    return $this->registered[$name];
    }
    }
    Registry::instance()->class1();
    Registry::instance()->class2();
    Registry::instance()->class3();

    Expected result:
    ----------------
    C:class1
    C:class2
    C:class3
    D:class3
    D:class2
    D:class1

    Actual result:
    --------------
    C:class1
    C:class2
    C:class3
    D:class1
    D:class2
    D:class3

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

    luke Guest

  2. #2

    Default #46169 [Com]: destruct in wrong order with static object

    ID: 46169
    Comment by: luke at cywh dot com
    Reported By: luke at cywh dot com
    Status: Open
    Bug Type: Scripting Engine problem
    Operating System: Linux
    PHP Version: 5.2.6
    New Comment:

    Just discovered it's not just static objects. If you create an object
    within a function in a local variable, it destructs after the function

    finishes (like it should). But if you track it in an array in the
    primary classes scope, it destructs incorrectly still. Adding the
    Registry in the results, you get:

    C:Registry
    C:class1
    C:class2
    C:class3
    D:Registry
    D:class1
    D:class2
    D:class3

    But I would expect this:

    C:Registry
    C:class1
    C:class2
    C:class3
    D:Registry
    D:class3
    D:class2
    D:class1

    or this?:

    C:Registry
    C:class1
    C:class2
    C:class3
    D:class3
    D:class2
    D:class1
    D:Registry

    Grrr... I'm not even sure. There is no consistency. 5.1.6 was "wrong",

    but at least it was consistently wrong.


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

    [2008-09-24 18:14:17] luke at cywh dot com

    Description:
    ------------
    This is related to a bug that was fixed in version 5.2.0, which you
    can read about here:

    http://bugs.php.net/bug.php?id=36759

    Basically if you were to initiate a class, the destruct order would be

    incorrect: "C1,C2,C3,D1,D2,D3". This was corrected in 5.2.0 to be
    "C1,C2,C3,D3,D2,C1".

    The problem, however, still persists if you create an object inside a
    static object. Code to recreate this issue is included in this bug
    report.

    If you initiate the classes without the Registry singleton, it
    destructs properly ($c1 = new class1()...).

    Testing this with 5.1.6, the destruct order is incorrect in both
    situations (as i'd expect). If you unset the objects in reverse order
    as they were created, both work correctly on 5.1.6 and 5.2.6.

    So a work-around for either version is to simply track the objects and

    unset them. But if you don't do this, the destruct order is still
    incorrect if creating your objects through a singleton object.

    Reproduce code:
    ---------------
    class shorten {
    public function __construct() { print 'C:' . get_class($this) . "<br
    />"; }
    public function __destruct() { print 'D:' . get_class($this) . "<br
    />"; }
    }
    class class1 extends shorten {}
    class class2 extends shorten {}
    class class3 extends shorten {}
    class Registry {
    static private $instance = null;
    private $registered = array();
    static public function instance() {
    if(self::$instance == null) self::$instance = new Registry();
    return self::$instance;
    }
    private function __call($name, $arguments) {
    if( ! isset($this->registered[$name]) ) $this->registered[$name] =
    new $name();
    return $this->registered[$name];
    }
    private function __get($name) {
    if( ! isset($this->registered[$name]) ) $this->registered[$name] =
    new $name();
    return $this->registered[$name];
    }
    }
    Registry::instance()->class1();
    Registry::instance()->class2();
    Registry::instance()->class3();

    Expected result:
    ----------------
    C:class1
    C:class2
    C:class3
    D:class3
    D:class2
    D:class1

    Actual result:
    --------------
    C:class1
    C:class2
    C:class3
    D:class1
    D:class2
    D:class3


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


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

    luke Guest

  3. #3

    Default #46169 [Opn->Bgs]: destruct in wrong order with static object

    ID: 46169
    Updated by: net
    Reported By: luke at cywh dot com
    -Status: Open
    +Status: Bogus
    Bug Type: Scripting Engine problem
    Operating System: Linux
    PHP Version: 5.2.6
    New Comment:

    Thank you for taking the time to write to us, but this is not
    a bug. Please double-check the doentation available at
    http://www.php.net/manual/ and the instructions on how to report
    a bug at http://bugs.php.net/how-to-report.php




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

    [2008-09-24 18:36:50] luke at cywh dot com

    Just discovered it's not just static objects. If you create an object
    within a function in a local variable, it destructs after the function

    finishes (like it should). But if you track it in an array in the
    primary classes scope, it destructs incorrectly still. Adding the
    Registry in the results, you get:

    C:Registry
    C:class1
    C:class2
    C:class3
    D:Registry
    D:class1
    D:class2
    D:class3

    But I would expect this:

    C:Registry
    C:class1
    C:class2
    C:class3
    D:Registry
    D:class3
    D:class2
    D:class1

    or this?:

    C:Registry
    C:class1
    C:class2
    C:class3
    D:class3
    D:class2
    D:class1
    D:Registry

    Grrr... I'm not even sure. There is no consistency. 5.1.6 was "wrong",

    but at least it was consistently wrong.

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

    [2008-09-24 18:14:17] luke at cywh dot com

    Description:
    ------------
    This is related to a bug that was fixed in version 5.2.0, which you
    can read about here:

    http://bugs.php.net/bug.php?id=36759

    Basically if you were to initiate a class, the destruct order would be

    incorrect: "C1,C2,C3,D1,D2,D3". This was corrected in 5.2.0 to be
    "C1,C2,C3,D3,D2,C1".

    The problem, however, still persists if you create an object inside a
    static object. Code to recreate this issue is included in this bug
    report.

    If you initiate the classes without the Registry singleton, it
    destructs properly ($c1 = new class1()...).

    Testing this with 5.1.6, the destruct order is incorrect in both
    situations (as i'd expect). If you unset the objects in reverse order
    as they were created, both work correctly on 5.1.6 and 5.2.6.

    So a work-around for either version is to simply track the objects and

    unset them. But if you don't do this, the destruct order is still
    incorrect if creating your objects through a singleton object.

    Reproduce code:
    ---------------
    class shorten {
    public function __construct() { print 'C:' . get_class($this) . "<br
    />"; }
    public function __destruct() { print 'D:' . get_class($this) . "<br
    />"; }
    }
    class class1 extends shorten {}
    class class2 extends shorten {}
    class class3 extends shorten {}
    class Registry {
    static private $instance = null;
    private $registered = array();
    static public function instance() {
    if(self::$instance == null) self::$instance = new Registry();
    return self::$instance;
    }
    private function __call($name, $arguments) {
    if( ! isset($this->registered[$name]) ) $this->registered[$name] =
    new $name();
    return $this->registered[$name];
    }
    private function __get($name) {
    if( ! isset($this->registered[$name]) ) $this->registered[$name] =
    new $name();
    return $this->registered[$name];
    }
    }
    Registry::instance()->class1();
    Registry::instance()->class2();
    Registry::instance()->class3();

    Expected result:
    ----------------
    C:class1
    C:class2
    C:class3
    D:class3
    D:class2
    D:class1

    Actual result:
    --------------
    C:class1
    C:class2
    C:class3
    D:class1
    D:class2
    D:class3


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


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

    jani@php.net Guest

Similar Threads

  1. Replies: 3
    Last Post: July 24th, 07:30 AM
  2. changing the static text object to others color
    By sengung webforumsuser@macromedia.com in forum Macromedia Flash Actionscript
    Replies: 0
    Last Post: January 22nd, 11:10 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139