rfc:class_name_scalars
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:class_name_scalars [2012/04/17 20:24] – Added considerations section ralphschindler | rfc:class_name_scalars [2012/09/14 15:15] – [Vote] ralphschindler | ||
---|---|---|---|
Line 3: | Line 3: | ||
* Date: 2012-04-17 | * Date: 2012-04-17 | ||
* Author: Ralph Schindler < | * Author: Ralph Schindler < | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
Line 31: | Line 31: | ||
</ | </ | ||
+ | ==== Real World Usage Scenarios ==== | ||
+ | |||
+ | 1. PHPUnit' | ||
+ | |||
+ | <code php> | ||
+ | |||
+ | use MyVendor\SomeComponent\TargetSubNs; | ||
+ | |||
+ | // inside a test case | ||
+ | $this-> | ||
+ | // as opposed to | ||
+ | $this-> | ||
+ | </ | ||
+ | |||
+ | 2. Doctrine | ||
+ | |||
+ | <code php> | ||
+ | |||
+ | use MyVendor\SomeComponent\TargetEntityNs as Entity; | ||
+ | |||
+ | // inside a test case | ||
+ | $entityManager-> | ||
+ | // as opposed to | ||
+ | $entityManager-> | ||
+ | |||
+ | </ | ||
+ | |||
+ | 3. Any Real (auto-wiring || auto-instantiating) Dependency Injection Container | ||
+ | |||
+ | <code php> | ||
+ | |||
+ | use MyVendor\SomeComponent\TargetNs as T; | ||
+ | |||
+ | // inside a test case | ||
+ | $dic-> | ||
+ | // as opposed to | ||
+ | $dic-> | ||
+ | |||
+ | </ | ||
+ | |||
+ | 4. General PHP Usage: | ||
+ | |||
+ | <code php> | ||
+ | |||
+ | use MyVendor\SomeComponent\TargetNs as T; | ||
+ | |||
+ | // reflection | ||
+ | $r = new ReflectionClass(T\Foo:: | ||
+ | |||
+ | // class_exists, | ||
+ | if (class_exists(T\Foo:: | ||
+ | |||
+ | </ | ||
===== Choice of syntax ===== | ===== Choice of syntax ===== | ||
Line 36: | Line 89: | ||
Furthermore the syntax resembles the semantically equivalent Java syntax '' | Furthermore the syntax resembles the semantically equivalent Java syntax '' | ||
+ | |||
+ | Note: since this feature reuses T_CLASS/ | ||
===== More examples ===== | ===== More examples ===== | ||
Line 46: | Line 101: | ||
namespace Foo\Bar { | namespace Foo\Bar { | ||
class Baz {} | class Baz {} | ||
- | var_dump(Moo:: | + | var_dump(Moo:: |
class Box { | class Box { | ||
public static function registerClassName($class = Baz::class) { | public static function registerClassName($class = Baz::class) { | ||
Line 60: | Line 115: | ||
var_dump(Baz:: | var_dump(Baz:: | ||
var_dump(Boo:: | var_dump(Boo:: | ||
- | var_dump(Moo:: | + | var_dump(Moo:: |
- | var_dump(\Moo:: | + | var_dump(\Moo:: |
$class = Baz::class; // assign class as scalar to var | $class = Baz::class; // assign class as scalar to var | ||
$x = new $class; // create new class from original scalar assignment | $x = new $class; // create new class from original scalar assignment | ||
Line 86: | Line 141: | ||
Do we: | Do we: | ||
- | * Throw a compile error? | + | * <del>Throw a compile error?</ |
- | * Resolve as best as possible, meaning error in non-class context, do a runtime lookup in a class context | + | * <del>Resolve as best as possible, meaning error in non-class context, do a runtime lookup in a class context</ |
+ | |||
+ | **Note:** (as of 9/8/12) | ||
+ | |||
+ | In the current patch, the following resolutions take place: | ||
+ | * self::class resolves the same as %%__CLASS__%% would | ||
+ | * static:: | ||
+ | * parent:: | ||
===== Patch ===== | ===== Patch ===== | ||
- | * Patch located here: https:// | + | * Pull Request |
+ | |||
+ | ===== Vote ===== | ||
+ | <doodle title=" | ||
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
+ | Note: This Vote has been closed as the RFC will be moved back to discussion at the time being while the RFC and associated patch become more mature. | ||
===== Changelog ===== | ===== Changelog ===== | ||
- | * 2012-04-17 Initially created by Ralph Schindler | + | |
+ | * 2012-09-08 Updated RFC and added link to Pull Request (which addresses considerations and on-list questions) | ||
rfc/class_name_scalars.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1