rfc:class_name_scalars
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:class_name_scalars [2012/09/14 15:15] – [Vote] ralphschindler | rfc:class_name_scalars [2017/09/22 13:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
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 97: | Line 97: | ||
<code php> | <code php> | ||
+ | |||
+ | --TEST-- | ||
+ | class name as scalar from ::class keyword | ||
+ | --FILE-- | ||
<?php | <?php | ||
namespace Foo\Bar { | namespace Foo\Bar { | ||
- | class Baz {} | + | class One { |
- | var_dump(Moo::class); // resolve in namespace | + | // compile time constants |
- | class Box { | + | const A = self:: |
- | public static function | + | const B = Two:: |
- | var_dump($class); | + | |
+ | | ||
+ | public static function run() { | ||
+ | | ||
+ | var_dump(static:: | ||
+ | var_dump(parent:: | ||
+ | var_dump(Baz:: | ||
+ | } | ||
+ | } | ||
+ | class Three extends Two { | ||
+ | // compile time static lookups | ||
+ | public static function | ||
+ | | ||
+ | $two = Baz::class, | ||
+ | $three = One::A, | ||
+ | $four = self::B | ||
+ | | ||
+ | var_dump($one, $two, $three, $four); | ||
} | } | ||
} | } | ||
- | | + | |
+ | var_dump(Moo::CLASS); // resolve in namespace | ||
} | } | ||
namespace { | namespace { | ||
use Bee\Bop as Moo, | use Bee\Bop as Moo, | ||
- | Foo\Bar\Baz; | + | Foo\Bar\One; |
- | var_dump(Baz::class); // resolve from use | + | echo " |
+ | var_dump(One::class); // resolve from use | ||
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 = One::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 | ||
- | var_dump($x); | + | var_dump($x); |
+ | Foo\Bar\Two:: | ||
+ | echo " | ||
+ | Foo\Bar\Three:: | ||
+ | echo " | ||
+ | Foo\Bar\Three:: | ||
} | } | ||
- | |||
?> | ?> | ||
- | --EXPECTF-- | + | --EXPECTF-- |
+ | In NS | ||
string(11) " | string(11) " | ||
- | string(11) " | + | Top |
- | string(11) " | + | string(11) " |
string(3) " | string(3) " | ||
string(7) " | string(7) " | ||
string(3) " | string(3) " | ||
- | object(Foo\Bar\Baz)#1 (0) { | + | object(Foo\Bar\One)#1 (0) { |
} | } | ||
+ | string(11) " | ||
+ | string(11) " | ||
+ | string(11) " | ||
+ | string(11) " | ||
+ | Parent | ||
+ | string(11) " | ||
+ | string(13) " | ||
+ | string(11) " | ||
+ | string(11) " | ||
+ | Compile Check | ||
+ | string(13) " | ||
+ | string(11) " | ||
+ | string(11) " | ||
+ | string(11) " | ||
</ | </ | ||
Line 144: | Line 186: | ||
* < | * < | ||
- | **Note:** (as of 9/8/12) | + | **Note:** (as of 1/18/13) |
In the current patch, the following resolutions take place: | In the current patch, the following resolutions take place: | ||
Line 150: | Line 192: | ||
* static:: | * static:: | ||
* parent:: | * parent:: | ||
+ | * static:: | ||
Line 169: | Line 212: | ||
* 2012-04-17 Initially created by Ralph Schindler | * 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) | * 2012-09-08 Updated RFC and added link to Pull Request (which addresses considerations and on-list questions) | ||
+ | * 2013-01-18 Updated RFC to reflect design decisions, updated the test/ | ||
rfc/class_name_scalars.1347635745.txt.gz · Last modified: 2017/09/22 13:28 (external edit)