[thelist] single quotes and arrays

Volkan Özçelik volkan.ozcelik at gmail.com
Sat Apr 23 21:08:02 CDT 2016

My guesstimate is:

In `$pageid = $_GET[pageid];` you are doing a direct assignment and hence
the PHP interpreter can get clever enough to "catch" what you meant.

In ` ""<option value=\"$row['id']\">$row['title']</option>\n" ` however, it
is string interpolation; so it’s an additional level of indirection, and
PHP interpreter is not ready to infer what you meant and erring out.

As a best practice you should always be using quoted attributes as not
using them may be mixed with a variable with the same name. (

e.g. `

title = 'daniel'
$_GET[ title ]
will resolve to $_GET['daniel'] which probably will be undefined.

Just my 2c.

Would love to hear other PHP experts’ ideas on that though.



On Sat, Apr 23, 2016 at 5:52 PM Garth Hagerman <hagerman at mcn.org> wrote:

> 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