Jump to content

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...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.