php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40354 POST/GET Arrays won't initialize properly
Submitted: 2007-02-04 17:10 UTC Modified: 2007-02-05 19:32 UTC
From: andreyra at chtivo dot ru Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.2.0 OS: Windows 2003 Server
Private report: No CVE-ID: None
 [2007-02-04 17:10 UTC] andreyra at chtivo dot ru
Description:
------------
I have found strange behaviour with PHP POST/GET arrays. With print_r() command I have see all contents of array, but if I trying to access to values of array directly - I have got errors.

I have test this code with:
php5.1.2
php5.2.0
php5.2-win32-200702041530
Apache2.0.58/win32/php5apache2.dll
Apache2.2.3/win32/php5apache2_2.dll
Apache2.2.4/win32/php5apache2_2.dll

And always I have same results.

In my php.ini:
register_globals    =   On
register_long_arrays    =   On
register_argc_argv  =   On
post_max_size       =   512M


Reproduce code:
---------------
<form name="topics" method="post">
<input type="text" name="topic[1]['name']" value="Some text"><br/>
<button onclick="this.form.submit(true);">POST</button>
</form>
<?php
    if (!isset($_POST['topic'])){
      return false;
     };
    if (!is_array($_POST['topic'])){
      return false;
     };
    foreach ($_POST['topic'] as $topic_id=>$arr){
      print_r($arr);
      if (!isset($arr['name'])){
        echo "<br/>\r\nERROR! NAME field is not set!\r\n";
        continue;
       };
      echo 'OK.';
     };

?>

Expected result:
----------------
OK.

Actual result:
--------------
ERROR! NAME field is not set!

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-02-05 09:25 UTC] tony2001@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.


 [2007-02-05 18:34 UTC] andreyra at chtivo dot ru
The strange behaviour consists in the fact of discrepancy between results of print_r() procedure and a real condition of a variable. 

In my sample print_r($arr) say:
Array ( ['name'] => Some text )

But in the next string, then I try to read $arr['name'] - PHP sayd "PHP Notice:  Undefined index:  name in test.php..."

Imho there is no difference - bogus my bug or not, the most important that I have got used to trust that results of print_r() procedure are used for debugging and always give out unequivocal result. On this example I have received a full refutation of my vision.
 [2007-02-05 18:40 UTC] tony2001@php.net
See the difference between:
  array("name"=>"value")
and
  array("\'name\'"=>"value")
 [2007-02-05 19:32 UTC] andreyra at chtivo dot ru
I'm sorry that's my fault.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 10:01:32 2024 UTC