From:             jbeall at heraldic dot us
Operating system: Linux
PHP version:      5.0.3
PHP Bug Type:     Arrays related
Bug description:  __get and __set are not called when property explicitly 
defined public or var

Description:
------------
If you give a form input a name that should be a numerically indexed
array, such as

<input type='text' name='fname[1]' />

It is not possible to directly access the variable via $_GET, $_POST, or
$_REQUEST.

Dumping the entire contents of the request using e.g. print_r reveals that
the form data is submitted, but it cannot be accessed via e.g.
$_POST['fname']['1'] or $_POST['fname'][1]

Presumably this happens because the PHP engine is doing type juggling. 
When a request variable is submitted and looks like an array, the PHP puts
it in an array and indexes the value at the string value '1'.  However,
when you try to access $_POST['fname']['1'] it sees that '1' could be an
integer, converts to an integer transparently to the developer, and of
course there is nothing stored at $_POST['fname'][1].  The data was stored
at $_POST['fname']['1'].

For whatever reason, embedding the variable in a string appears to solve
the problem.  E.g., "{$_POST['test'][1]}" works

Reproduce code:
---------------
echo "<pre>"; // So we can use \n for formatting
echo <<<EOT
<form method='GET' action='{$_SERVER['PHP_SELF']}'>
        <input type='text' name='test[1]' value='{$_REQUEST['test'][1]}'/>
        <input type='submit'/>
</form>
EOT;

echo '('.gettype($test[1]).') value='.$test[1]."\n";
echo '('.gettype($test[1]).') value='.$test['1']."\n";
echo "But it works if we embed in a string --->
{$_REQUEST['test'][1]}\n";
var_dump($_REQUEST['test']);

// Put a string variable in the textbox and submit.
// If using GET method, URL might look like 
// bugTest.php?test%5B1%5D=any+string+here

Expected result:
----------------
(string) value=any string here
(string) value=any string here
But it works if we embed in a string ---> any string here
Array
(
    [1] => any string here
)

Actual result:
--------------
(NULL) value=
(NULL) value=
But it works if we embed in a string ---> any string here
Array
(
    [1] => any string here
)

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

Reply via email to