rfc:class_name_scalars

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
rfc:class_name_scalars [2012/09/11 14:32] – [Request for Comments: Cution As Scalar Via class Keyword] lass Name Resol ralphschindlerrfc:class_name_scalars [2012/09/14 15:16] – [Request for Comments: Class Name Resolution As Scalar Via class Keyword] ralphschindler
Line 3: Line 3:
   * Date: 2012-04-17   * Date: 2012-04-17
   * Author: Ralph Schindler <ralph.at.ralphschindler.com>   * Author: Ralph Schindler <ralph.at.ralphschindler.com>
-  * Status: Voting+  * Status: Under Discussion
   * First Published at: http://wiki.php.net/rfc/class_name_scalars   * First Published at: http://wiki.php.net/rfc/class_name_scalars
  
Line 31: Line 31:
 </code> </code>
  
 +==== Real World Usage Scenarios ====
 +
 +1. PHPUnit's Mocking
 +
 +<code php>
 +
 +use MyVendor\SomeComponent\TargetSubNs;
 +
 +// inside a test case
 +$this->getMock(TargetSubNs\Foo::class);
 +// as opposed to
 +$this->getMock('MyVendor\SomeComponent\TargetSubNs\Foo');
 +</code>
 +
 +2. Doctrine
 +
 +<code php>
 +
 +use MyVendor\SomeComponent\TargetEntityNs as Entity;
 +
 +// inside a test case
 +$entityManager->find(Entity\User::class, 5);
 +// as opposed to
 +$entityManager->find('MyVendor\SomeComponent\TargetEntityNs\User', 5);
 +
 +</code>
 +
 +3. Any Real (auto-wiring || auto-instantiating) Dependency Injection Container
 +
 +<code php>
 +
 +use MyVendor\SomeComponent\TargetNs as T;
 +
 +// inside a test case
 +$dic->newInstance(T\Foo::class);
 +// as opposed to
 +$dic->newInstance('MyVendor\SomeComponent\TargetEntityNs\Foo');
 +
 +</code>
 +
 +4. General PHP Usage:
 +
 +<code php>
 +
 +use MyVendor\SomeComponent\TargetNs as T;
 +
 +// reflection
 +$r = new ReflectionClass(T\Foo::class); // instead of new ReflectionClass('MyVendor\SomeComponent\TargetNs\Foo');
 +
 +// class_exists, also applies to any php function that takes a class name (is_subclass_of, get_class_methods, etc)
 +if (class_exists(T\Foo::class, true)) {} // instead of class_exists('MyVendor\SomeComponent\TargetNs\Foo')
 +
 +</code>
 ===== Choice of syntax ===== ===== Choice of syntax =====
  
Line 88: Line 141:
 Do we: Do we:
  
-  * Throw a compile error? +  * <del>Throw a compile error?</del> 
-  * 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</del> 
 + 
 +**Note:** (as of 9/8/12)
  
-Note: (as of 9/8/12) 
 In the current patch, the following resolutions take place: In the current patch, the following resolutions take place:
-  * self::class resolves the same as __CLASS__ would+  * self::class resolves the same as %%__CLASS__%% would
   * static::class resolves the same as get_called_class() would   * static::class resolves the same as get_called_class() would
   * parent::class resolves the same as get_parent_class() would, (in fact, would return false if not inherited.)   * parent::class resolves the same as get_parent_class() would, (in fact, would return false if not inherited.)
Line 105: Line 159:
  
  
-<doodle title="Should the ::class feature be merged to master?" auth="ralphschindler" voteType="single" closed="false">+<doodle title="Should the ::class feature be merged to master?" auth="ralphschindler" voteType="single" closed="true">
    * Yes    * Yes
    * No    * No
 </doodle> </doodle>
  
 +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 =====
  
rfc/class_name_scalars.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1