Object in array turns into reference when I access it.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alex Farran

    #1

    Object in array turns into reference when I access it.


    Can anyone explain this? I'm running PHP Version 4.3.7

    <?php
    class foo {
    function bar() {
    }
    }

    $array["foo"] = new foo();

    var_dump($array );
    // Returns:
    // array(1) {
    // ["foo"]=>
    // object(foo)(0) {
    // }
    // }

    $array["foo"]->bar();

    var_dump($array );
    // Returns
    // array(1) {
    // ["foo"]=>
    // &object(foo) (0) { <-- How did that happen?
    // }
    // }
    ?>
    --

    __o Alex Farran - PHP / MySQL Web application development
    _`\<,_ site: www.alexfarran.com phone: 01273 474065
    (_)/ (_) blog: alexfarran.blog spot.com mobile: 07790 389330
  • Janwillem Borleffs

    #2
    Re: Object in array turns into reference when I access it.

    Alex Farran wrote:[color=blue]
    > Can anyone explain this? I'm running PHP Version 4.3.7
    >[/color]

    See: http://bugs.php.net/bug.php?id=11543


    JW



    Comment

    • Alex Farran

      #3
      Re: Object in array turns into reference when I access it.

      Janwillem Borleffs writes:
      [color=blue]
      > Alex Farran wrote:[color=green]
      >> Can anyone explain this? I'm running PHP Version 4.3.7
      >>[/color][/color]
      [color=blue]
      > See: http://bugs.php.net/bug.php?id=11543[/color]

      Thank you. So it is a bug. The last comment talks about the
      __clone() method in Zend 2, which seems slightly tangential to the
      problem. Can someone with PHP5 installed run my script and show me
      what happens?

      --

      __o Alex Farran - PHP / MySQL Web application development
      _`\<,_ site: www.alexfarran.com phone: 01273 474065
      (_)/ (_) blog: alexfarran.blog spot.com mobile: 07790 389330

      Comment

      • Sebastian Lauwers

        #4
        Re: Object in array turns into reference when I access it.

        Alex Farran wrote:
        [color=blue]
        > Can someone with PHP5 installed run my script and show me
        > what happens?[/color]

        Yes:

        array(1) {
        ["foo"]=>
        object(foo)#1 (0) {
        }
        }
        array(1) {
        ["foo"]=>
        object(foo)#1 (0) {
        }
        }

        HTH,

        PS: I used the script you gave in the first post, if you need me to test
        another, i'd love to help.

        Best regards,
        Sebastian

        Comment

        • Alex Farran

          #5
          Re: Object in array turns into reference when I access it.

          Sebastian Lauwers writes:
          [color=blue]
          > Alex Farran wrote:[color=green]
          >> Can someone with PHP5 installed run my script and show me
          >> what happens?[/color][/color]
          [color=blue]
          > Yes:[/color]

          Thanks. That's much more sensible behaviour. One more reason to
          switch to PHP5 ASAP.

          --

          __o Alex Farran - PHP / MySQL Web application development
          _`\<,_ site: www.alexfarran.com phone: 01273 474065
          (_)/ (_) blog: alexfarran.blog spot.com mobile: 07790 389330

          Comment

          Working...