Skip to content

Add expression support with "new" keyword. - #62

Closed
mageekguy wants to merge 2 commits into
php:masterfrom
mageekguy:createInstanceFromExpression
Closed

mageekguy wants to merge 2 commits into
php:masterfrom
mageekguy:createInstanceFromExpression

Conversation

@mageekguy

Copy link
Copy Markdown

It's already possible to create class instance with :

  1. a string:
  2. a variable:
  3. a variable variable:

This commit add the possibility to use an expression :

It's already possible to create class instance with :
1) a string:
   <?php
   class Foo {}
   $foo = new Foo;
   ?>
2) a variable:
   <?php
   class Foo {}
   $class = 'Foo';
   $foo = new $class;
   ?>
3) a variable variable:
   <?php
   class Foo {}
   $class = 'Foo';
   $name = 'class';
   $foo = new $$name;
   ?>
This commit add the possibility to use an expression :
   <?php
   class Foo {}
   $oo = 'oo';
   $foo = new {'f' . $oo};
   ?>
@winks

winks commented Apr 20, 2012

Copy link
Copy Markdown
Contributor

Finding such occurrences is usually a good indication to punch the author of the code, but of course that doesn't necessarily mean the language shouldn't support it.
So if it doesn't break stuff, yeah ;)

@php-pulls

Copy link
Copy Markdown

Comment on behalf of lstrojny at php.net:

We discussed this issue briefly on IRC and we feel it is a language change that requires an RFC. Have a look at https://wiki.php.net/rfc/voting how the RFC process works. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants