1

I'm looking for more information about the PHP feature that looks like:

$obj->{$prop};
$obj->{$method}();

What is it called? Is it documented? Where?

Edit:

To clarify - I'm asking about the syntax with the curly braces that you can use to have dynamic complex lookups of object properties or methods. For instance, as reported by php -l, these are valid:

echo $obj->{"val"};               // property lookup with string literal
echo $obj->{$method()->{$var}}(); // complex method lookup
echo $obj::${$other::$something}; // static property lookup

But this is not:

echo $obj::{$other::$something};  // class constant lookup

I'm searching for something "official" that outlines what is and isn't valid with that kind of syntax, if such a document exists.

Stephen Searles
  • 971
  • 6
  • 18
  • http://stackoverflow.com/questions/10333016/how-to-access-object-properties-with-names-like-integers – Claudiordgz Mar 19 '14 at 03:31
  • @Claudiordgz That's interesting, but I'm looking for "official" information about what's valid or not with this feature (for whatever that means in PHP). I'm working on tools for people who write PHP, but I'm at a loss on specific information about this feature beyond my trial and error. – Stephen Searles Mar 19 '14 at 03:37

2 Answers2

1

The official document on the 'braces syntax' when used within strings is here:

http://www.php.net/manual/en/language.types.string.php

look at the section: 'Variable Parsing' (complex) for details on using it to lookup object properties etc.

The other time you may need to use the 'braces syntax' is if you use 'variable variables'.

This is when you want to use a variable to hold the name of another variable.

this is documented here as well as possible uses:

http://www.php.net/manual/en/language.variables.variable.php

Ryan Vincent
  • 4,483
  • 7
  • 22
  • 31
  • Hmm, this looks specific to variable parsing within strings. I think the feature I'm asking about is distinct and might have some differences. It does seem related though. – Stephen Searles Mar 19 '14 at 05:44
0

http://us1.php.net/call_user_func

mixed call_user_func ( callable $callback [, mixed $parameter [, mixed $... ]] )

To get variable would just be

$obj->$variable
Joshua Bixler
  • 531
  • 2
  • 6
  • Thanks, but I know the general use for the feature. I'm working on tools for PHP and I need to know more specific information on what's valid and what isn't with this feature, but I haven't been able to find any documentation. I don't see anything relevant at the link you posted. – Stephen Searles Mar 19 '14 at 03:40
  • http://us1.php.net/manual/en/language.types.callable.php This page explains what valid callable variables are. Is that what you mean? – Joshua Bixler Mar 19 '14 at 03:41
  • I don't see it there either. I mean the syntax with the curly braces that lets you do complex dynamic things to lookup an object property or call an object method. I'm starting to feel like this feature is like the secret menu at In-n-out... – Stephen Searles Mar 19 '14 at 03:46
  • You are right, I can't find anything official on the curly braces syntax. Will keep looking. – Claudiordgz Mar 19 '14 at 03:51
  • 1
    I think this one might be as close as you get. http://www.php.net/manual/en/language.variables.variable.php – Joshua Bixler Mar 19 '14 at 03:54
  • @Claudiordgz I just added some more clarification to the question itself. Thanks for your help. – Stephen Searles Mar 19 '14 at 03:54