Professional Web Applications Themes

strange foreach behaviour - PHP Development

I have come up against a very strange problem. I currently have no idea how to even approach attempting to fix it......

Sponsored Links
  1. #1

    Default strange foreach behaviour


    I have come up against a very strange problem. I currently have no idea how
    to even approach attempting to fix it...

    Sponsored Links
    Martin Peck Guest

  2. #2

    Default Re: strange foreach behaviour

    My apologies for the last post - somehow managed to send whilst attempting
    to copy and paste... d'oh.
    I'd like to try again.

    I have come up against a very strange problem. I currently have no idea how
    to even approach attempting to fix it...

    In the following code snippet, $this->items is an array of objects - each of
    these objects is one of two object types (with similar interfaces). There
    is nothing that unusual in the these few lines:

    foreach ($this->items as $code => $item) {
    var_dump($this->items[$code]);
    var_dump($item);
    etc.
    }

    but after successfully calling this piece of code a number of times in my
    application, I get the following output:

    object(citem)(2) {
    ["q"]=>
    int(1)
    ["c"]=>
    string(3) "157"
    }
    NULL
    Fatal error: Call to a member function on a non-object in
    /var/www/local/ge/include/product.php4 on line 58

    I have no comprehension how it is that the two var_dump() commands can
    produce different outputs. Can anyone suggest what sort of thing I need to
    be looking at?!

    Any help very gratefully received,
    regards,
    Martin

    Martin Peck Guest

  3. #3

    Default Re: strange foreach behaviour

    Martin Peck wrote:
    > My apologies for the last post - somehow managed to send whilst attempting
    > to copy and paste... d'oh.
    > I'd like to try again.
    >
    > I have come up against a very strange problem. I currently have no idea how
    > to even approach attempting to fix it...
    >
    > In the following code snippet, $this->items is an array of objects - each of
    > these objects is one of two object types (with similar interfaces). There
    > is nothing that unusual in the these few lines:
    >
    > foreach ($this->items as $code => $item) {
    > var_dump($this->items[$code]);
    > var_dump($item);
    > etc.
    > }
    >
    > but after successfully calling this piece of code a number of times in my
    > application, I get the following output:
    >
    > object(citem)(2) {
    > ["q"]=>
    > int(1)
    > ["c"]=>
    > string(3) "157"
    > }
    > NULL
    > Fatal error: Call to a member function on a non-object in
    > /var/www/local/ge/include/product.php4 on line 58
    >
    > I have no comprehension how it is that the two var_dump() commands can
    > produce different outputs. Can anyone suggest what sort of thing I need to
    > be looking at?!
    >
    > Any help very gratefully received,
    > regards,
    > Martin
    Are your running that foreach iteration code outside of a class?

    SIGHUP Guest

Similar Threads

  1. #40608 [NEW]: break within foreach causes strange behaviour
    By eric dot broersma at phil dot uu dot nl in forum PHP Bugs
    Replies: 16
    Last Post: March 23rd, 08:01 AM
  2. strange SQL behaviour
    By platho in forum IBM DB2
    Replies: 1
    Last Post: September 6th, 04:05 PM
  3. Very strange behaviour
    By Mark in forum AIX
    Replies: 0
    Last Post: September 1st, 04:19 PM
  4. Strange CLI behaviour
    By Frank Passek in forum PHP Development
    Replies: 0
    Last Post: August 10th, 07:45 PM
  5. Strange <img> tag behaviour when encapsulated in IF
    By Gianpiero Colagiacomo in forum ASP
    Replies: 10
    Last Post: July 5th, 02:08 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