Weird behavior of volt 'length' filter on object

Hi Guys,

I'm using phalcon 2.1.0 RC1. Latest windows binary available on the blog.

Throw this in any volt file:

<?php $test = (object) array((object) array('test')); ?>
<?php var_dump(count($test)); ?>
<?php var_dump($this->length($test)); ?>
<?php var_dump(gettype($test)); ?>
<?php var_dump($test); ?>

The output is as follows:

int 1
int 0
string 'object' (length=6)
  public 0 => 
      public 0 => string 'test' (length=4)

Does anyone know why the volt filter is returning 0?

I don't see anything wrong with the function in zephir:

That looks weird. What php version you are using ?

edited Jun '16

I'm using PHP Version 5.6.14 x86 MSVC11

PHPinfo here: PHPinfo phalcon module: phalcon

edited Jun '16

This is also happening on PHP Version 5.5.36 by the way.


I guess this is related:

So it shouldn't really work properly in the first place. Only phalcon counts 0 instead of 1. I think I'll switch my code to use arrays.

Im guessing you right, just use array.

I had this length filter issue as well on PHP 7.1 and Phalcon 3.2.2.

I found that {% if object is not empty %} works and let's you continue using the object rather than an array.

Just for the sake of safety, I now use {% if object is defined and object is not empty %} and it performs entirely as expected.