cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

[BUG]: Volt Render Notice : Undefined index: name

Open kevcomparadise opened this issue 3 years ago • 2 comments

Describe the bug When we try to access a public method of a sub class contained in a public property of a root class, Volt generates a Notice. PS : Return value OK

To Reproduce Steps to reproduce the behavior:

  • 1 : Create Controller and pass to volt an object contain an sub-object
class TestController extend Controller {

   public function indexAction()
   {

       $subObject = new class {

            public function getValue() {
                return 'Value';
            }

        };

        $rootObject = new class ($subObject) {

            public $sub_object = null;

            public function __construct($subObject)
              {
                  $this->sub_object =  $subObject;
              }
        };

        $this->view->testObject = $rootObject
  }
}

  • 2 : Create related view (/test/index.volt)
{{ testObject.sub_object.getValue() }}

Note : If we use a getter for sub_object (like : getsubObject()) it work

Expected behavior Render without notice

Details

  • Phalcon version: 5.0RC4
  • PHP Version: 8.1.6
  • Operating System: Debian
  • Installation type: installing via package manager (PECL)
  • Server: Apache

kevcomparadise avatar Sep 16 '22 15:09 kevcomparadise

Does it work if you use different files for classes vs the new class syntax?

I have not tested this but I am not sure Volt works with that (yet).

niden avatar Sep 16 '22 16:09 niden

Does it work if you use different files for classes vs the new class syntax?

I have not tested this but I am not sure Volt works with that (yet).

Nop same result This work with Phalcon 3.4

kevcomparadise avatar Sep 17 '22 05:09 kevcomparadise

I'm also experiencing this issue (in v5.0.2). A workaround that seems to work for my situation is to first set a variable, and then display that variable. Using your example:

Change:

{{ testObject.sub_object.getValue() }}

To:

{% set foo = testObject.sub_object.getValue() %}
{{ foo }}

colinpieper avatar Sep 30 '22 09:09 colinpieper

same problem here. The solution @colinpieper mentioned works but far from ideal especially when you have many templates, like @kevcomparadise said this used to work in Phalcon 3.4.5. Can we expect this to be fixed soon?

rtmotiondev avatar Oct 07 '22 09:10 rtmotiondev

I have the same issue and the releases from v5.0.0RC4 to v5.0.4 have the issue but the release v5.0.0RC3 works fine

palcoder avatar Oct 19 '22 01:10 palcoder

Any update on when this will be fixed please?

ccc-nghia-le avatar Oct 25 '22 00:10 ccc-nghia-le

We are working on this one guys. Hopefully we can figure out where it comes from.

I checked a bit the code and it seems to fail in the code to ob_start() so that might be happening in Zephir.

niden avatar Oct 25 '22 17:10 niden

This has been resolved in https://github.com/phalcon/cphalcon/pull/16187.

Thank you @kevcomparadise @colinpieper

niden avatar Oct 26 '22 21:10 niden