Issues

ZF-11456: Add returnsReference support to Zend_CodeGenerator_Php_Method

Issue Type: Patch Created: 2011-06-08T16:08:53.000+0000 Last Updated: 2011-10-13T03:32:04.000+0000 Status: Open Fix version(s): Reporter: John Crenshaw (bugslayer) Assignee: Ralph Schindler (ralph) Tags: - Zend_CodeGenerator

Related issues: Attachments:

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).

<pre class="highlight">
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

Posted by Ryan Mauger (bittarman) on 2011-06-08T16:13:27.000+0000

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!

Posted by John Crenshaw (bugslayer) on 2011-06-09T00:15:11.000+0000

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.

Posted by John Crenshaw (bugslayer) on 2011-10-13T03:32:04.000+0000

Signed agreement is in the mail.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts