Jump to content

Creating Variables


subesc

Recommended Posts

Hey everyone,

 

I'm studying for my Zend PHP 5 Certification Exam and I came across a question that I was hoping I could get an explanation for.

 

The question lists a few choices and asks which of the choices are valid PHP variables.

 

The options are:

[*]@$foo

[*]&$variable

[*]${0x0}

[*]$variable

[*]$0x0

 

I know what the answers are, but I don't know why ${0x0} can be a variable. Doesn't this evaluate to 0? If so, then why would it allow me to create a variable that starts with a number?

 

Is the only way that I can call it using the syntax ${0x0} or is there something else I'm missing?

 

Simply curious.

Thanks for the help!

Link to comment
https://forums.phpfreaks.com/topic/160099-creating-variables/
Share on other sites

Is the only way that I can call it using the syntax ${0x0} or is there something else I'm missing?

Other ways to get at the same variable would include: ${0}, ${00}, ${11 - 6 - 5}, ${substr('120', -1)} (ie, anything that results eventually in string value of "0").  You can't go via the  $GLOBALS array as the key ($GLOBALS["0"]) is cast as an integer and $GLOBALS[0] does not exist and of course you cannot use $0 as that is an invalid variable name and will throw a parse error.

 

Well after trying it myself, did a little searching, I found this...

Good to see my blog getting a search engine visitor.  :)

Link to comment
https://forums.phpfreaks.com/topic/160099-creating-variables/#findComment-846243
Share on other sites

  • 1 year later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.