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)
object(stdClass)[178]
  public 0 => 
    object(stdClass)[176]
      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: https://github.com/phalcon/cphalcon/blob/96422c673ff544b9468643b31ea42897d343e092/phalcon/mvc/view/engine/volt.zep#L130

That looks weird. What php version you are using ?



1.6k
edited Jun '16

I'm using PHP Version 5.6.14 x86 MSVC11

PHPinfo here: PHPinfo phalcon module: phalcon



1.6k
edited Jun '16

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

Edit:

I guess this is related: http://stackoverflow.com/questions/1314745/php-count-an-stdclass-object

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.