rfc:returntypehint

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
rfc:returntypehint [2010/07/28 20:08] – New exampel feliperfc:returntypehint [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 72: Line 72:
 } }
 // PHP Fatal error:  Declaration of Foo::bar() must be compatible with that of ITest::bar() in ... on line 7 // PHP Fatal error:  Declaration of Foo::bar() must be compatible with that of ITest::bar() in ... on line 7
 +</code>
 +
 +=== Using a namespaced class ===
 +
 +<code php>
 +<?php
 +
 +namespace foo {
 +class foo { }
 +class bar extends foo { }
 +}
 +
 +namespace bar {
 +class bar {
 + public function \foo\foo test() {
 + return new \foo\bar;
 + }
 +}
 +
 +$bar = new bar;
 +$bar->test(); // ok
 +}
 </code> </code>
  
Line 94: Line 116:
  
 $func = new ReflectionMethod('foo::test'); $func = new ReflectionMethod('foo::test');
-var_dump($func->getReturnType()); // "Test" +var_dump($func->getReturnTypeHint());   // "Test" 
-var_dump($func->returnsObject()); // true +var_dump($func->returnsObject());       // true
-var_dump($func->getReturnClass());  // "Test"+
 </code> </code>
  
Line 109: Line 130:
  
 $func = new ReflectionFunction('abc'); $func = new ReflectionFunction('abc');
-var_dump($func->getReturnType()); // scalar+var_dump($func->getReturnTypeHint()); // scalar 
 +var_dump($func->returnsScalar());     // true
 </code> </code>
  
 +=== Using "self" as type ===
 +
 +<code php>
 +<?php
 +
 +class foo {
 + function self bar() {
 + return new foo;
 + }
 +}
 +
 +$func = new ReflectionMethod('foo::bar');
 +var_dump($func->getReturnTypeHint()); // foo
 +var_dump($func->returnsObject());     // true
 +</code>
  
 ===== Patch ===== ===== Patch =====
  
-Comming soon+  * Engine + Reflection: http://felipe.ath.cx/diff/returntypehint.diff 
 +  * Tests: http://felipe.ath.cx/diff/tests/return_typehint_tests.zip
rfc/returntypehint.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1