note 104851 added to function.array-walk
| From: | Maxim at osu1 dot php dot net | Date: | Mon, 11 Jul 2011 19:23:00 +0000 |
| Subject: | note 104851 added to function.array-walk | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-181421@lists.php.net to get a copy of this message | ||
Note that using array_walk with intval is inappropriate.
There are many examples on internet that suggest to use following code to safely escape $_POST
arrays of integers:
<?php
array_walk($_POST['something'],'intval'); // does nothing in PHP 5.3.3
?>
It works in _some_ older PHP versions (5.2), but is against specifications. Since intval() does not
modify it's arguments, but returns modified result, the code above has no effect on the array
and will leave security hole in your website.
You can use following instead:
<?php
$_POST['something'] = array_map(intval,$_POST['something']);
?>
----
Server IP: 69.147.83.197
Probable Submitter: 89.235.218.33
----
Manual Page -- http://www.php.net/manual/en/function.array-walk.php
Edit -- https://master.php.net/note/edit/104851
Del: integrated -- https://master.php.net/note/delete/104851/integrated
Del: useless -- https://master.php.net/note/delete/104851/useless
Del: bad code -- https://master.php.net/note/delete/104851/bad+code
Del: spam -- https://master.php.net/note/delete/104851/spam
Del: non-english -- https://master.php.net/note/delete/104851/non-english
Del: in docs -- https://master.php.net/note/delete/104851/in+docs
Del: other reasons-- https://master.php.net/note/delete/104851
Reject -- https://master.php.net/note/reject/104851
Search -- https://master.php.net/manage/user-notes.php