ZF-11456: Add returnsReference support to Zend_CodeGenerator_Php_Method

Description

Here's a small patch that adds returnsReference() support to Zend_CodeGenerator_Php_Method. Without this, methods with reference returning signatures cannot be properly generated (potentially creating bugs in code that depends on the correct operation of code generated from reflected methods).


Index: Method.php
===================================================================
--- Method.php  (revision 1098)
+++ Method.php  (working copy)
@@ -54,6 +54,11 @@
     protected $_isFinal = false;
 
     /**
+     * @var bool
+     */
+    protected $_returnsReference = false;
+    
+    /**
      * @var array
      */
     protected $_parameters = array();
@@ -90,6 +95,8 @@
             $method->setVisibility(self::VISIBILITY_PUBLIC);
         }
 
+        $method->setReturnsReference($reflectionMethod->returnsReference());
+
         $method->setStatic($reflectionMethod->isStatic());
 
         $method->setName($reflectionMethod->getName());
@@ -114,6 +121,24 @@
     }
 
     /**
+     * setReturnsReference()
+     *
+     * @param bool $returnsReference
+     */
+    public function setReturnsReference($returnsReference)
+    {
+        $this->_returnsReference = ($returnsReference) ? true : false;
+    }
+
+    /**
+     * returnsReference()
+     */
+    public function returnsReference()
+    {
+        return $this->_returnsReference;
+    }
+    
+    /**
      * setParameters()
      *
      * @param array $parameters
@@ -207,7 +232,9 @@
 
         $output .= $this->getVisibility()
             . (($this->isStatic()) ? ' static' : '')
-            . ' function ' . $this->getName() . '(';
+            . ' function '
+            . (($this->returnsReference()) ? ' & ' : '')
+            . $this->getName() . '(';
 
         $parameters = $this->getParameters();
         if (!empty($parameters)) {

Comments

Hi John,

Thanks for the patch to contribute to ZF, but I notice that you don't appear to have a CLA on file, if you do, you should get in touch with Ralph Schindler and ask him to assign you the correct groups so that you can attach patches as an attachment rather than inline, otherwise, you should sign the cla (http://framework.zend.com/wiki/display/…) and return it before contributing code, otherwise your contributions may go unused!

Bleh. Are there any alternate methods that don't require me to dig up archaic equipment like scanners, fax machines, and/or stamps? There are plenty of legally binding ways to get the same protection entirely digitally.

If you can't accept the patch without this, I'll see what I can do.

Signed agreement is in the mail.