[thelist] single quotes and arrays

Symeon Charalabides symeon at systasis.com
Sun Apr 24 05:38:05 CDT 2016


Hi Garth,

Since you know what it takes to stop the notice, namely to surround pageid in quote (single or double, it doesn't matter), you should practice that. Here's the explanation you are after:

When you pass the variable $pageid to another script via the GET method, the actual variable $pageid is unset after populating the superglobal array $_GET with its value. So what you fetch then when you call $_GET['pageid'] is the value of the element with key "pageid" and that's why it should be quoted.

To make it more concrete, let's say you're passing the following 2 parameters from page A to page B via get:
$pageid = 34
$userid = 65

When page B is called, the situation is as follows:
$pageid: unset so it doesn't exist anymore
$userid: unset so it doesn't exist anymore
$_GET: Array(
    'pageid' => '34',
    'userid' => '65
)

As for why your echo example dies, you'd have to supply the actual fatal error message but I suspect it's a different issue.

I hope that helps,

Symeon Charalabides (cosmopolite trainee)
-----------------------------------------
http://www.systasis.com
http://twitter.com/bluesymeon
http://www.linkedin.com/in/symeon


>  -------Original Message-------
>  From: Garth Hagerman <hagerman at mcn.org>
>  To: thelist at lists.evolt.org
>  Subject: [thelist] single quotes and arrays
>  Sent: 24 Apr '16 00:52
>  
>  Hi everybody-
>  Since The List is alive again (hooray!), here's a query.
>  I've been making the same boo-boo over and over for years. I have a rote mechanical understanding of what to do about it, but I do not understand the conceptual background.
>  
>  In PHP, I pass info to another page using a form. The page receiving the info has a line like this:
>  $pageid = $_GET[pageid];
>  
>  This works, so there doesn't seem to be anything wrong, so I do it over and over and over. But it logs something like this into the error_log:
>  "PHP Notice:  Use of undefined constant pageid - assumed 'pageid' ".
>  
>  Since this happens a lot, the error_log gets to be a very large file.
>  
>  So, I understand how to stop getting that notice: put single quotes around pageid.
>  But why? pageid isn't a string, it's the name of an array element. If I do the same single quote thing with other arrays, something like:
>  echo("<option value=\"$row['id']\">$row['title']</option>\n");
>  it's a fatal error and the whole page explodes.
>  
>  I've tried to find a reasonable explanation online, but haven't found anything which makes the little "eureka!" light over my head light up.
>  
>    Thanks in advance
>    Garth
>                                
>  
>                             * * * * * * * * * * * * * * * *
>                                 my online portfolio
>  
>                            http://garthhagerman.com/
>  
>  
>  --
>  
>  * * Please support the community that supports you.  * *
>  http://evolt.org/help_support_evolt/
>  
>  For unsubscribe and other options, including the Tip Harvester
>  and archives of thelist go to: http://lists.evolt.org
>  Workers of the Web, evolt !
>  


More information about the thelist mailing list