Ali
Ali

Reputation: 267317

Using arrays without putting the key in quotes?

It used to be that if you did this:

$foo[bar] = true;

instead of:

$foo['bar'] = true;

you would get a 'Notice' error. However now with PHP 5, I no longer seem to get this error? Has this been changed?

Upvotes: 1

Views: 194

Answers (3)

Your Common Sense
Your Common Sense

Reputation: 158005

In fact, this question has nothing to do with arrays. It's string bar you're typing against rules, as strings should be always quoted in PHP.

While array keys has nothing to do with quotes. In PHP you can use almost every language construct that returns scalar value to be used as a key. Only square brackets belongs to array syntax. Everything between them is just going to be regular PHP expression with it's usual rules.

Upvotes: 1

Matthew
Matthew

Reputation: 48314

They still trigger that notice, so you must have disabled notices from being displayed on screen.

Upvotes: 2

Mārtiņš Briedis
Mārtiņš Briedis

Reputation: 17772

Probably error reporting is turned off.

Try at top of the code:

ini_set("display_errors", true);
error_reporting(E_ALL);

Upvotes: 3

Related Questions