note 112771 deleted from function.array-push by googleguy

From: Date: Mon, 22 Jul 2013 00:54:54 +0000
Subject: note 112771 deleted from function.array-push by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-195699@lists.php.net to get a copy of this message
Note Submitter: pdiceinc at gmail dot com ---- 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!

« previous php.notes (#195699) next »