foreach problem moving from php v4.3.0 to php v4.3.10

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Patrick Russell

    foreach problem moving from php v4.3.0 to php v4.3.10

    I am trying to figure out why the code listed below works in php v4.3.0 but
    not in v4.3.10:

    $string = "Param1=Val1;Pa ram2=Val2;Param 3=Val3";
    $exploded_strin g = explode(";",$st ring);
    foreach($explod ed_string as $param){
    list($key, $value) = split("=",$para m);
    ...additional code...
    }

    It works fine in v4.3.0, but when I run it on a server running v4.3.10 I get
    an error because $param is an Array. It should be a regular scaler variable.

    On the first iteration $param should equal 'Param1=Val1'
    On the Second iteration $param should equel 'Param2=Val2'

    so on an so forth...

    Any thoughts or suggestions

    Thanks Patrick


  • Jacob Atzen

    #2
    Re: foreach problem moving from php v4.3.0 to php v4.3.10

    On 2005-04-06, Patrick Russell <prussell@snpen t.com> wrote:[color=blue]
    > I am trying to figure out why the code listed below works in php v4.3.0 but
    > not in v4.3.10:
    >
    > $string = "Param1=Val1;Pa ram2=Val2;Param 3=Val3";
    > $exploded_strin g = explode(";",$st ring);
    > foreach($explod ed_string as $param){
    > list($key, $value) = split("=",$para m);
    > ...additional code...
    > }
    >
    > It works fine in v4.3.0, but when I run it on a server running v4.3.10 I get
    > an error because $param is an Array. It should be a regular scaler variable.
    >
    > On the first iteration $param should equal 'Param1=Val1'
    > On the Second iteration $param should equel 'Param2=Val2'
    >
    > so on an so forth...
    >
    > Any thoughts or suggestions[/color]

    What do you get if you var_dump($param )? And what if you
    var_dump($explo ded_string)?

    Your code works fine on my PHP 5.0.3 system.

    --
    Cheers
    - Jacob Atzen

    Comment

    • Csaba Gabor

      #3
      Re: foreach problem moving from php v4.3.0 to php v4.3.10

      works fine in V. 5.0.4-dev on Win XP Pro
      Csaba

      Patrick Russell wrote:[color=blue]
      > I am trying to figure out why the code listed below works in php v4.3.0 but
      > not in v4.3.10:
      >
      > $string = "Param1=Val1;Pa ram2=Val2;Param 3=Val3";
      > $exploded_strin g = explode(";",$st ring);
      > foreach($explod ed_string as $param){
      > list($key, $value) = split("=",$para m);
      > ...additional code...
      > }
      >
      > It works fine in v4.3.0, but when I run it on a server running v4.3.10 I get
      > an error because $param is an Array. It should be a regular scaler variable.
      >
      > On the first iteration $param should equal 'Param1=Val1'
      > On the Second iteration $param should equel 'Param2=Val2'
      >
      > so on an so forth...
      >
      > Any thoughts or suggestions
      >
      > Thanks Patrick
      >
      >[/color]

      Comment

      • Patrick Russell

        #4
        Re: foreach problem moving from php v4.3.0 to php v4.3.10

        Based on the replies, I created a test php script and it works, but the
        original script still errors. Below are the var_dump results.

        var_dump($explo ded_string) =
        array(3) { [0]=> string(11) "Param1=Val 1" [1]=> string(11) "Param2=Val 2"
        [2]=> string(11) "Param3=Val 3" }

        var_dump($param ) =
        array(2) { [0]=> string(11) "Param1=Val 1" [1]=> int(0) } var_dump of $param

        array(2) { [0]=> string(11) "Param2=Val 2" [1]=> int(1) } var_dump of $param

        array(2) { [0]=> string(11) "Param3=Val 3" [1]=> int(2) } var_dump of $param


        Thanks

        Patrick

        "Jacob Atzen" <jacob@aub.dk > wrote in message
        news:slrnd57uep .2iu2.jacob@tan k.aub.dk...[color=blue]
        > On 2005-04-06, Patrick Russell <prussell@snpen t.com> wrote:[color=green]
        > > I am trying to figure out why the code listed below works in php v4.3.0[/color][/color]
        but[color=blue][color=green]
        > > not in v4.3.10:
        > >
        > > $string = "Param1=Val1;Pa ram2=Val2;Param 3=Val3";
        > > $exploded_strin g = explode(";",$st ring);
        > > foreach($explod ed_string as $param){
        > > list($key, $value) = split("=",$para m);
        > > ...additional code...
        > > }
        > >
        > > It works fine in v4.3.0, but when I run it on a server running v4.3.10 I[/color][/color]
        get[color=blue][color=green]
        > > an error because $param is an Array. It should be a regular scaler[/color][/color]
        variable.[color=blue][color=green]
        > >
        > > On the first iteration $param should equal 'Param1=Val1'
        > > On the Second iteration $param should equel 'Param2=Val2'
        > >
        > > so on an so forth...
        > >
        > > Any thoughts or suggestions[/color]
        >
        > What do you get if you var_dump($param )? And what if you
        > var_dump($explo ded_string)?
        >
        > Your code works fine on my PHP 5.0.3 system.
        >
        > --
        > Cheers
        > - Jacob Atzen[/color]


        Comment

        • Jacob Atzen

          #5
          Re: foreach problem moving from php v4.3.0 to php v4.3.10

          On 2005-04-06, Patrick Russell <prussell@snpen t.com> wrote:[color=blue]
          > Based on the replies, I created a test php script and it works, but the
          > original script still errors. Below are the var_dump results.
          >
          > var_dump($explo ded_string) =
          > array(3) { [0]=> string(11) "Param1=Val 1" [1]=> string(11) "Param2=Val 2"
          > [2]=> string(11) "Param3=Val 3" }
          >
          > var_dump($param ) =
          > array(2) { [0]=> string(11) "Param1=Val 1" [1]=> int(0) } var_dump of $param
          >
          > array(2) { [0]=> string(11) "Param2=Val 2" [1]=> int(1) } var_dump of $param
          >
          > array(2) { [0]=> string(11) "Param3=Val 3" [1]=> int(2) } var_dump of $param[/color]

          This really makes no sense at all. Please show the actual code producing
          the bug with var_dump()'s inserted and also the output from a run of
          said code.

          --
          Cheers
          - Jacob Atzen

          Comment

          • Patrick Russell

            #6
            Re: foreach problem moving from php v4.3.0 to php v4.3.10

            Below is the actual code being run.

            function parse_connect_s tring ($connstring)
            {
            $exploded_strin g = explode(";",$co nnstring);
            //debug
            var_dump($explo ded_string);
            echo "<br>";
            //------------
            foreach($explod ed_string as $param){
            //debug
            var_dump($param );
            echo "<br>";
            //----------------
            list($key, $value) = split("=",$para m);
            if (isset($this->{$key})) {
            $this->{$key} = $value;
            }
            if (!$this->dbname == "") {
            $this->ActiveDB = $this->dbname;
            }
            }

            Below is the output of the dump:

            array(4) { [0]=> string(14) "host=localhost " [1]=> string(7) "user=me" [2]=>
            string(14) "pwd=mypassword " [3]=> string(11) "dbname=myd b" }
            array(2) { [0]=> string(14) "host=localhost " [1]=> int(0) }
            array(2) { [0]=> string(7) "user=me" [1]=> int(1) }
            array(2) { [0]=> string(14) "pwd=mypassword " [1]=> int(2) }
            array(2) { [0]=> string(11) "dbname=myd b" [1]=> int(3) }

            you can also see the actual output at the following address:




            "Jacob Atzen" <jacob@aub.dk > wrote in message
            news:slrnd582vl .2iu2.jacob@tan k.aub.dk...[color=blue]
            > On 2005-04-06, Patrick Russell <prussell@snpen t.com> wrote:[color=green]
            > > Based on the replies, I created a test php script and it works, but the
            > > original script still errors. Below are the var_dump results.
            > >
            > > var_dump($explo ded_string) =
            > > array(3) { [0]=> string(11) "Param1=Val 1" [1]=> string(11) "Param2=Val 2"
            > > [2]=> string(11) "Param3=Val 3" }
            > >
            > > var_dump($param ) =
            > > array(2) { [0]=> string(11) "Param1=Val 1" [1]=> int(0) } var_dump of[/color][/color]
            $param[color=blue][color=green]
            > >
            > > array(2) { [0]=> string(11) "Param2=Val 2" [1]=> int(1) } var_dump of[/color][/color]
            $param[color=blue][color=green]
            > >
            > > array(2) { [0]=> string(11) "Param3=Val 3" [1]=> int(2) } var_dump of[/color][/color]
            $param[color=blue]
            >
            > This really makes no sense at all. Please show the actual code producing
            > the bug with var_dump()'s inserted and also the output from a run of
            > said code.
            >
            > --
            > Cheers
            > - Jacob Atzen[/color]


            Comment

            • Patrick Russell

              #7
              Re: foreach problem moving from php v4.3.0 to php v4.3.10

              sorry about the link, you will need to goto:



              then click on the Buy Now link

              Patrick
              "Jacob Atzen" <jacob@aub.dk > wrote in message
              news:slrnd582vl .2iu2.jacob@tan k.aub.dk...[color=blue]
              > On 2005-04-06, Patrick Russell <prussell@snpen t.com> wrote:[color=green]
              > > Based on the replies, I created a test php script and it works, but the
              > > original script still errors. Below are the var_dump results.
              > >
              > > var_dump($explo ded_string) =
              > > array(3) { [0]=> string(11) "Param1=Val 1" [1]=> string(11) "Param2=Val 2"
              > > [2]=> string(11) "Param3=Val 3" }
              > >
              > > var_dump($param ) =
              > > array(2) { [0]=> string(11) "Param1=Val 1" [1]=> int(0) } var_dump of[/color][/color]
              $param[color=blue][color=green]
              > >
              > > array(2) { [0]=> string(11) "Param2=Val 2" [1]=> int(1) } var_dump of[/color][/color]
              $param[color=blue][color=green]
              > >
              > > array(2) { [0]=> string(11) "Param3=Val 3" [1]=> int(2) } var_dump of[/color][/color]
              $param[color=blue]
              >
              > This really makes no sense at all. Please show the actual code producing
              > the bug with var_dump()'s inserted and also the output from a run of
              > said code.
              >
              > --
              > Cheers
              > - Jacob Atzen[/color]


              Comment

              • Jacob Atzen

                #8
                Re: foreach problem moving from php v4.3.0 to php v4.3.10

                On 2005-04-06, Patrick Russell <prussell@snpen t.com> wrote:[color=blue]
                > Below is the actual code being run.
                >
                > function parse_connect_s tring ($connstring)
                > {
                > $exploded_strin g = explode(";",$co nnstring);
                > //debug
                > var_dump($explo ded_string);
                > echo "<br>";
                > //------------
                > foreach($explod ed_string as $param){
                > //debug
                > var_dump($param );
                > echo "<br>";
                > //----------------
                > list($key, $value) = split("=",$para m);
                > if (isset($this->{$key})) {
                > $this->{$key} = $value;
                > }
                > if (!$this->dbname == "") {
                > $this->ActiveDB = $this->dbname;
                > }
                > }
                >
                > Below is the output of the dump:
                >
                > array(4) { [0]=> string(14) "host=localhost " [1]=> string(7) "user=me" [2]=>
                > string(14) "pwd=mypassword " [3]=> string(11) "dbname=myd b" }
                > array(2) { [0]=> string(14) "host=localhost " [1]=> int(0) }
                > array(2) { [0]=> string(7) "user=me" [1]=> int(1) }
                > array(2) { [0]=> string(14) "pwd=mypassword " [1]=> int(2) }
                > array(2) { [0]=> string(11) "dbname=myd b" [1]=> int(3) }[/color]

                Still doesn't make any sense. I just tried to run your code on a PHP
                4.3.10 system and got the expected output:

                array(2) {
                [0]=>
                string(5) "p1=v1"
                [1]=>
                string(5) "p2=v2"
                }
                <br>string(5) "p1=v1"
                <br>string(5) "p2=v2"

                This of course by calling your function with 'p1=v1;p2=v2' as parameter.

                I just found the following bug <http://bugs.php.net/bug.php?id=3091 4>
                which sounds like the symptoms you're experiencing. Are you by any
                chance using ZendOptimizer 2.5.5? Or any other kind of extra processing
                of your PHP scripts?

                --
                Cheers
                - Jacob Atzen

                Comment

                • Patrick Russell

                  #9
                  Re: foreach problem moving from php v4.3.0 to php v4.3.10

                  I am not running the ZendOptimizer. You are right though, it doesn't make
                  any sense. The bug looks exactly like what I am experiencing. I also can't
                  understand why it works on the test page I created at
                  http://128.241.54.143/foreach.php , but not the original script.


                  Patrick

                  "Jacob Atzen" <jacob@aub.dk > wrote in message
                  news:slrnd58cg0 .2iu2.jacob@tan k.aub.dk...[color=blue]
                  > On 2005-04-06, Patrick Russell <prussell@snpen t.com> wrote:[color=green]
                  > > Below is the actual code being run.
                  > >
                  > > function parse_connect_s tring ($connstring)
                  > > {
                  > > $exploded_strin g = explode(";",$co nnstring);
                  > > //debug
                  > > var_dump($explo ded_string);
                  > > echo "<br>";
                  > > //------------
                  > > foreach($explod ed_string as $param){
                  > > //debug
                  > > var_dump($param );
                  > > echo "<br>";
                  > > //----------------
                  > > list($key, $value) = split("=",$para m);
                  > > if (isset($this->{$key})) {
                  > > $this->{$key} = $value;
                  > > }
                  > > if (!$this->dbname == "") {
                  > > $this->ActiveDB = $this->dbname;
                  > > }
                  > > }
                  > >
                  > > Below is the output of the dump:
                  > >
                  > > array(4) { [0]=> string(14) "host=localhost " [1]=> string(7) "user=me"[/color][/color]
                  [2]=>[color=blue][color=green]
                  > > string(14) "pwd=mypassword " [3]=> string(11) "dbname=myd b" }
                  > > array(2) { [0]=> string(14) "host=localhost " [1]=> int(0) }
                  > > array(2) { [0]=> string(7) "user=me" [1]=> int(1) }
                  > > array(2) { [0]=> string(14) "pwd=mypassword " [1]=> int(2) }
                  > > array(2) { [0]=> string(11) "dbname=myd b" [1]=> int(3) }[/color]
                  >
                  > Still doesn't make any sense. I just tried to run your code on a PHP
                  > 4.3.10 system and got the expected output:
                  >
                  > array(2) {
                  > [0]=>
                  > string(5) "p1=v1"
                  > [1]=>
                  > string(5) "p2=v2"
                  > }
                  > <br>string(5) "p1=v1"
                  > <br>string(5) "p2=v2"
                  >
                  > This of course by calling your function with 'p1=v1;p2=v2' as parameter.
                  >
                  > I just found the following bug <http://bugs.php.net/bug.php?id=3091 4>
                  > which sounds like the symptoms you're experiencing. Are you by any
                  > chance using ZendOptimizer 2.5.5? Or any other kind of extra processing
                  > of your PHP scripts?
                  >
                  > --
                  > Cheers
                  > - Jacob Atzen[/color]


                  Comment

                  • Jacob Atzen

                    #10
                    Re: foreach problem moving from php v4.3.0 to php v4.3.10

                    On 2005-04-06, Patrick Russell <prussell@snpen t.com> wrote:[color=blue]
                    > I am not running the ZendOptimizer. You are right though, it doesn't
                    > make any sense. The bug looks exactly like what I am experiencing. I
                    > also can't understand why it works on the test page I created at
                    > http://128.241.54.143/foreach.php , but not the original script.[/color]

                    I can only guess that somehow their configurations must differ. Try
                    comparing the output of phpinfo() on the two servers.

                    --
                    Cheers
                    - Jacob Atzen

                    Comment

                    • Patrick Russell

                      #11
                      Re: foreach problem moving from php v4.3.0 to php v4.3.10

                      Jason,

                      First I want to thank you for your assistance. You have been very helpful.
                      It appears I was running a few ioncube encoded scripts. The scripts were
                      classes included into the main script along with some included un-encoded
                      scripts. After switching the offending included scripts with un-encoded
                      ones, the problem was resolved. You pointed me in the right direction with
                      your link to the php bugs page. The encoded scripts are needed for security
                      reasons. My options are to replace all 'foreach' loops with 'for' loops. I
                      have tested this and know it works. Im also going to see if I can workaround
                      this issue by encoding all the included scripts. I think I will be having
                      some discussions with the ionCube support staff.

                      Thanks again for your assistance.

                      Patrick

                      SNP Enterprises


                      "Jacob Atzen" <jacob@aub.dk > wrote in message
                      news:slrnd58jep .2iu2.jacob@tan k.aub.dk...[color=blue]
                      > On 2005-04-06, Patrick Russell <prussell@snpen t.com> wrote:[color=green]
                      > > I am not running the ZendOptimizer. You are right though, it doesn't
                      > > make any sense. The bug looks exactly like what I am experiencing. I
                      > > also can't understand why it works on the test page I created at
                      > > http://128.241.54.143/foreach.php , but not the original script.[/color]
                      >
                      > I can only guess that somehow their configurations must differ. Try
                      > comparing the output of phpinfo() on the two servers.
                      >
                      > --
                      > Cheers
                      > - Jacob Atzen[/color]


                      Comment

                      • Wayne

                        #12
                        Re: foreach problem moving from php v4.3.0 to php v4.3.10

                        On Wed, 06 Apr 2005 14:13:53 GMT, "Patrick Russell"
                        <prussell@snpen t.com> wrote:
                        [color=blue]
                        >It works fine in v4.3.0, but when I run it on a server running v4.3.10 I get
                        >an error because $param is an Array. It should be a regular scaler variable.[/color]

                        This is a bug in the Zend Optimizer (assuming you have it installed).
                        You need to upgrade to the latest Zend Optimizer and that will resolve
                        the problem. I encountered this myself.

                        Comment

                        • Jacob Atzen

                          #13
                          Re: foreach problem moving from php v4.3.0 to php v4.3.10

                          On 2005-04-06, Patrick Russell <prussell@snpen t.com> wrote:[color=blue]
                          > Jason,[/color]

                          I assume you mean Jacob ;-) Anyways, glad I could help.

                          --
                          Cheers
                          - Jacob Atzen

                          Comment

                          Working...