Issues

ZF-9501: "zf create action" causes malformed PHP when non-empty action methods already exist

Issue Type: Bug Created: 2010-03-21T12:07:22.000+0000 Last Updated: 2012-06-01T17:30:59.000+0000 Status: Resolved Fix version(s): - 1.12.0 (27/Aug/12)

Reporter: Stanislav Malyshev (stas) Assignee: Adam Lundrigan (adamlundrigan) Tags: - Zend_Tool

  • FixForZF1.12
  • zf-caretaker-adamlundrigan

Related issues: - ZF-9310

Attachments:

Description

I have controller which has this code in the start of the class:

public function preDispatch()
{
    $acl = Zend_Registry::get('acl');

            if(!$acl->isAllowed(Zend_Registry::get('role'), 'admin', $this->getRequest()->action)) {
                if(!Zend_Auth::getInstance()->hasIdentity()) {
                    $this->_forward('noauth', 'error');
                } else {
                    $this->_forward('noacl', 'error');
                }
            }
}

when I run zf create action for this file, the resulting PHP file comes out broken - this method has one closing brace } missing.

Comments

Posted by Stanislav Malyshev (stas) on 2010-03-21T12:15:57.000+0000

Also just noticed - it does not preserve the formatting of the document completely. While all the lines are ok, indentation is often messed up.

Posted by Rodrigo Neves (xmajox) on 2010-07-16T01:46:52.000+0000

This also happens to me. Together with the tab messup, it really becomes a pain to use zend tool.

All the controller gets wrecked every single time a new action is added wich really starts to get into you once the controller starts to get big.

Posted by Rodrigo Neves (xmajox) on 2010-07-16T02:19:49.000+0000

Just upgraded to 1.10.6 to make sure, and it still happens.

It removes any closing bracket that's right before the method's one. i.e.:

function yadayadaAction(){

/* lots of code */

if (something){ ... } }

The if's closing bracket gets removed.

Posted by Youssef Eldakar (snowsmash) on 2010-08-03T01:00:28.000+0000

I can confirm this on 1.10.3.

Youssef Eldakar Bibliotheca Alexandrina

Posted by Ramon Henrique Ornelas (ramon) on 2010-11-20T10:10:06.000+0000

This problem is related to Zend_Reflection_Method::getBody().

Greetings Ramon

Posted by Ramon Henrique Ornelas (ramon) on 2010-11-20T10:12:54.000+0000

Is related to with issue ZF-9018.

Posted by Max Gordon (mgordon) on 2011-01-05T12:41:08.000+0000

I've noticed that whenever I have a try{}catch() the code breaks up and the comments get an additional empty line, heres code:

<pre class="highlight">
class IndexController extends Zend_Controller_Action {
    public function init() {
    }

    /**
     * a test action
     */
    public function funkyAction() {
        $this->view->title = "COOOL";
    }

    public function indexAction() {
        try {
            $this->view->title = "Testing Zend_Tool bug";
        } catch (Exception $exc) {
            echo $exc->getTraceAsString();
        }
    }

    /**
     * a test action
     */
    public function unfunkyAction() {
        $this->view->title = "UNCOOOL";
    }
}



<pre class="highlight">
class IndexController extends Zend_Controller_Action
{
    public function init()
    {
    }

    /**
     * a test action
     *
     */
    public function funkyAction()
    {
        $this->view->title = "COOOL";
    }

    public function indexAction()
    {
        try {
            $this->view->title = "Testing Zend_Tool bug";
        } catch (Exception $exc) {
            echo $exc->getTraceAsString();
        
    }

    /**
     * a test action
     *
     */
    public function unfunkyAction()
    {
        $this->view->title = "UNCOOOL";
    }

    public function testAction()
    {
        // action body
    }
}

Note missing } in the try and the extra comment line: /** * a test action * */

This was done with the ZF 1.11.2

Posted by Simone Marchioni (simo75) on 2011-02-03T03:20:59.000+0000

Same problem here. ZF version: 1.11.0 If I add an action with a command like this:

zf create action

there are 2 kind of problems:

  1. The controller source is bad indented
  2. The last closing bracket inside EVERY action method is removed, leaving you with corrupted PHP code

Note: the error #2 is for every structure control enclosed with curly braces, so this problem is valid if you have a while, an if, a try/catch, and so on... The closing bracket is stripped away.

I'm trying to teach ZF inside our company but If the basic Tools like Zend_Tool don't function properly I can't tell people to switch to them. This bug is almost an year old: hope to see it fixed soon. I'll vote for it.

Posted by Oliver Spooner (ospooner) on 2011-02-16T09:04:21.000+0000

Not that this will stop the indentation problem, but it only removes a curly bracket if it is the last thing before the closing bracket of the function. This means you can stop Zend Tool from breaking the code by adding a commented line before the closing bracket:

public function myAction() { if($whatever) { } // Comment added here stops the curly bracket getting removed from the line above. }

Still not ideal, but it does at least mean you can add actions using zf.

Posted by Daniel Kraaij (daank) on 2011-04-07T12:03:10.000+0000

I'm having the same problem, but only in the following situation.

<pre class="highlight">
    public function removeAction()
    {
        if (NULL !== ($itemId = $this->_getParam('id', null))) {
            $cartMapper = new Application_Model_CartMapper();
            if ($cartMapper->removeItem($itemId)) {
                $this->_redirect('/cart');
            }
        }
    }




<pre class="highlight">

    public function removeAction()
    {
        if (NULL !== ($itemId = $this->_getParam('id', null))) {
            $cartMapper = new Application_Model_CartMapper();
            if ($cartMapper->removeItem($itemId)) {
                $this->_redirect('/cart');
            }
        
    }

Posted by Adam Lundrigan (adamlundrigan) on 2011-10-17T16:27:14.000+0000

This issue stems from problems with Zend_Reflection_Method::getBody, as outlined in ZF-9018. An interim fix has been suggested there.

Posted by Adam Lundrigan (adamlundrigan) on 2012-06-01T17:30:59.000+0000

Fixed in ZF-9501

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