note 112771 added to function.array-push
| From: | pdiceinc at gmail dot com | Date: | Sun, 21 Jul 2013 22:46:20 +0000 |
| Subject: | note 112771 added to function.array-push | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-195698@lists.php.net to get a copy of this message | ||
On some hosts you may need to name your variables without underscore. I was banging my head for over
4 hours until I realised that the following code didn't work:
if (!isset($_SESSION['product_url']))
{
$_SESSION['product_url'] = array();
} else {
array_push($_SESSION['product_url'], $_POST['product_url']);
}
because the variable contained an underscore (_) in its name. When renamed to just
"producturl" everything goes smoothly.
Working code:
if (!isset($_SESSION['producturl']))
{
$_SESSION['producturl'] = array();
} else {
array_push($_SESSION['producturl'], $_POST['product_url']);
}
The problem is that when array_push is called it does not recognise the variable as an array but
just as plain variable instead and overrides its value. I haven't figured the exact reason, but
I suppose it has something to do with disabled features of cpanel because of security issues.
Another guess is a php bug I may have been dealing with for the past 4 hours. The PHP version I was
using with this code is 5.2.17
Naming your variables properly may save you quite some time, even though looking like a simple issue
it can drive you crazy until you figure it out:) Hope this saved someone a little time. Cheers!
----
Server IP: 69.147.83.199
Probable Submitter: 78.83.105.40
----
Manual Page -- http://php.net/manual/en/function.array-push.php
Edit -- https://master.php.net/note/edit/112771
Del: integrated -- https://master.php.net/note/delete/112771/integrated
Del: useless -- https://master.php.net/note/delete/112771/useless
Del: bad code -- https://master.php.net/note/delete/112771/bad+code
Del: spam -- https://master.php.net/note/delete/112771/spam
Del: non-english -- https://master.php.net/note/delete/112771/non-english
Del: in docs -- https://master.php.net/note/delete/112771/in+docs
Del: other reasons-- https://master.php.net/note/delete/112771
Reject -- https://master.php.net/note/reject/112771
Search -- https://master.php.net/manage/user-notes.php