-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
$compiler->compileString() returns FALSE instead of a string #2198
Comments
1.2.6 only had a change in Phalcon\Security, there's no way it could affect Volt |
Using git I see that my last commit to the volt.php file is dated June 9, 2013 with the message: "added the 'minustospace' filter, that replaces minus with spaces". |
Tried to downgrade and nothing changed. Probably is something I have changed but I can't figure out what. If I remove the following statement $compiler->addFilter('minustospace',
function($resolvedArgs, $exprArgs) {
return "str_replace('-', ' ', '".$resolvedArgs."')";
}
); I get an exception because the program can't find the filter, else I get a "No data received" in Chrome and the page is not displayed. Any idea? I can't even debug because the template is not generated when the filter is added. At this point I don't think it's a Phalcon bug, but any hint can be useful to find a solution. |
OK, dunno what happens here, but this code returns FALSE: $volt = new \Phalcon\Mvc\View\Engine\Volt($this->view, $this->di);
$compiler = $volt->getCompiler();
$compiler->addFilter('ucwords', 'ucwords');
var_dump($compiler->compileString('{{ "hello"|ucwords }}')); should return: // string '<?php echo ucwords('hello'); ?>' (length=31) instead it returns: // false So it's definitely a bug. Please try it and let me know how can I help you. |
Executing this test: <?php
$di = new Phalcon\DI\FactoryDefault();
$di['view'] = function(){
return new Phalcon\Mvc\View();
};
$volt = new \Phalcon\Mvc\View\Engine\Volt($di['view'], $di);
$compiler = $volt->getCompiler();
$compiler->addFilter('ucwords', 'ucwords');
var_dump($compiler->compileString('{{ "hello"|ucwords }}')); It outputs: string(31) "<?php echo ucwords('hello'); ?>" Could you please update my test to demonstrate the bug? |
When a closure is provided the filter doesn't work. See the code below: $volt = new \Phalcon\Mvc\View\Engine\Volt($di['view'], $di);
$compiler = $volt->getCompiler();
$compiler->addFilter('minustospace',
function($resolvedArgs, $exprArgs) {
return "str_replace('-', ' ', '".$resolvedArgs."')";
}
);
$compiler->addFilter('ucwords', 'ucwords');
$compiler->addFilter('likeucwords',
function($resolvedArgs, $exprArgs) {
return "ucwords('".$resolvedArgs."')";
}
);
var_dump($compiler->compileString('{{ "it-works"|ucwords }}')); // Works.
var_dump($compiler->compileString('{{ "it-works"|upper }}')); // Works.
var_dump($compiler->compileString('{{ "it-does-not-work"|likeucwords }}')); // Doesn't work.
var_dump($compiler->compileString('{{ "it-does-not-work"|minustospace }}')); // Doesn't work. |
I have just tested it under php 5.5 and it works. Are you on windows? see #2269 |
I'm on Mac OS X version 10.7.5 with PHP 5.5.10. Did you try on Linux? |
Yes I did, CentOS with php 5.5.9 from CLI. Did you try from cli? Just put the test code in a file and then run php -f [your_filename].php Here's my full test file: <?
$di = new Phalcon\DI\FactoryDefault();
$di['view'] = function(){
return new Phalcon\Mvc\View();
};
$volt = new \Phalcon\Mvc\View\Engine\Volt($di['view'], $di);
$compiler = $volt->getCompiler();
$compiler->addFilter('minustospace',
function($resolvedArgs, $exprArgs) {
return "str_replace('-', ' ', '".$resolvedArgs."')";
}
);
$compiler->addFilter('ucwords', 'ucwords');
$compiler->addFilter('likeucwords',
function($resolvedArgs, $exprArgs) {
return "ucwords('".$resolvedArgs."')";
}
);
var_dump($compiler->compileString('{{ "it-works"|ucwords }}')); // Works.
var_dump($compiler->compileString('{{ "it-works"|upper }}')); // Works.
var_dump($compiler->compileString('{{ "it-does-not-work"|likeucwords }}')); // Doesn't work.
var_dump($compiler->compileString('{{ "it-does-not-work"|minustospace }}')); // Doesn't work.
?> I'm getting
|
Wait LOL I think i saw the problem, there's double quotes around the string when the closure is used, how did I not see that? Let me try with php 5.3. |
php -f lippo.php string(34) "" |
This is the <?php
use Phalcon\DI\FactoryDefault as DependencyInjector;
use Phalcon\Mvc\Application as Application;
$loader = new \Phalcon\Loader();
$loader->register();
$di = new DependencyInjector();
$di['view'] = function(){
return new Phalcon\Mvc\View();
};
$volt = new \Phalcon\Mvc\View\Engine\Volt($di['view'], $di);
$compiler = $volt->getCompiler();
$compiler->addFilter('minustospace',
function($resolvedArgs, $exprArgs) {
return "str_replace('-', ' ', '".$resolvedArgs."')";
}
);
$compiler->addFilter('ucwords', 'ucwords');
$compiler->addFilter('likeucwords',
function($resolvedArgs, $exprArgs) {
return "ucwords(".$resolvedArgs.")";
}
);
var_dump($compiler->compileString('{{ "it-works"|ucwords }}'));
var_dump($compiler->compileString('{{ "it-works"|upper }}'));
var_dump($compiler->compileString('{{ "it-does-not-work"|likeucwords }}'));
var_dump($compiler->compileString('{{ "it-does-not-work"|minustospace }}')); It's a segmentation fault, something related memory allocation I think. |
Tested under MacOSX 10.8.5 and php 5.3 (default installed), no segmentation fault. Can you rebuild phalcon in debug mode and then run it under gdb? See these instructions: cd cphalcon/ext
#reinstall phalcon in debug mode
sudo ./install
#run gdb with php cli
gdb --args /usr/bin/php -f testvolt.php
#when you see gdb cli, input:
run
#when it segfaults, input:
bt
#and then paste your input here |
gdb /usr/bin/php -f ../../lippo.php GNU gdb 6.3.50-20050815 (Apple version gdb-1822) (Sun Aug 5 03:00:42 UTC 2012) warning: Could not find object file "/Volumes/work/macports/var/macports/build/_Volumes_work_macports_var_macports_sources_rsync.macports.org_release_tarballs_ports_archivers_bzip2/bzip2/work/bzip2-1.0.6/huffman.o" - no debug information available for "huffman.c". warning: Could not find object file "/Volumes/work/macports/var/macports/build/_Volumes_work_macports_var_macports_sources_rsync.macports.org_release_tarballs_ports_archivers_bzip2/bzip2/work/bzip2-1.0.6/crctable.o" - no debug information available for "crctable.c". warning: Could not find object file "/Volumes/work/macports/var/macports/build/_Volumes_work_macports_var_macports_sources_rsync.macports.org_release_tarballs_ports_archivers_bzip2/bzip2/work/bzip2-1.0.6/randtable.o" - no debug information available for "randtable.c". warning: Could not find object file "/Volumes/work/macports/var/macports/build/_Volumes_work_macports_var_macports_sources_rsync.macports.org_release_tarballs_ports_archivers_bzip2/bzip2/work/bzip2-1.0.6/compress.o" - no debug information available for "compress.c". warning: Could not find object file "/Volumes/work/macports/var/macports/build/_Volumes_work_macports_var_macports_sources_rsync.macports.org_release_tarballs_ports_archivers_bzip2/bzip2/work/bzip2-1.0.6/decompress.o" - no debug information available for "decompress.c". ...... done "/Users/fff/Downloads/cphalcon/ext/../../lippo.php" is not a core dump: File format not recognized At this time, nothing happens. |
Sorry, i forgot the --args parameter: gdb --args /usr/bin/php -f testvolt.php |
Same result, except for the starting program now is /usr/bin/php -f lippo.php On Apr 2, 2014, at 5:50 PM, maxgalbu wrote:
|
If not even your gdb works correctly I can't help you past this point, sorry. Here's my gdb output if it helps:
|
Finally I got gdb working. Here it is: (gdb) run
Starting program: /usr/bin/php -f lippo.php
string(34) "<?php echo ucwords('it-works'); ?>"
string(46) "<?php echo Phalcon\Text::upper('it-works'); ?>"
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000028
0x0000000100d81f44 in xdebug_add_stack_frame ()
(gdb) bt
#0 0x0000000100d81f44 in xdebug_add_stack_frame ()
#1 0x0000000100d73c36 in xdebug_execute_internal ()
#2 0x00000001001b1dc7 in zend_call_function ()
#3 0x000000010216d4c4 in phalcon_call_user_function (object_pp=0x0, obj_ce=0x0, type=phalcon_fcall_function, function_name=0x7fff5fbfa830, retval_ptr_ptr=0x7fff5fbfbb60, param_count=2, params=0x7fff5fbfad30) at fcall.c:429
#4 0x000000010216d7b1 in phalcon_call_func_aparams (return_value_ptr=0x7fff5fbfbb60, func_name=0x10252aa9a "call_user_func_array", func_length=20, param_count=2, params=0x7fff5fbfad30) at fcall.c:508
#5 0x00000001023019c0 in phalcon_return_call_function (return_value=0x100af0510, return_value_ptr=0x7fff5fbfbb60, func=0x10252aa9a "call_user_func_array", func_len=20, param_count=2, params=0x7fff5fbfad30) at fcall.h:563
#6 0x0000000102303f33 in zim_Phalcon_Mvc_View_Engine_Volt_Compiler_resolveFilter (ht=2, return_value=0x100af0510, return_value_ptr=0x7fff5fbfbb60, this_ptr=0x100aed8f8, return_value_used=1) at compiler.c:1329
#7 0x0000000102168861 in phalcon_execute_internal (execute_data_ptr=0x7fff5fbfb1e0, fci=0x7fff5fbfb338, return_value_used=1) at phalcon.c:53
#8 0x0000000100d73d20 in xdebug_execute_internal ()
#9 0x00000001001b1dc7 in zend_call_function ()
#10 0x000000010216d4c4 in phalcon_call_user_function (object_pp=0x7fff5fbfb548, obj_ce=0x102d2ca60, type=phalcon_fcall_method, function_name=0x7fff5fbfb4e0, retval_ptr_ptr=0x7fff5fbfbb60, param_count=2, params=0x7fff5fbfb9f8) at fcall.c:429
#11 0x000000010216dc60 in phalcon_call_class_method_aparams (return_value_ptr=0x7fff5fbfbb60, ce=0x102d2ca60, type=phalcon_fcall_method, object=0x100aed8f8, method_name=0x10252b28c "resolvefilter", method_len=13, param_count=2, params=0x7fff5fbfb9f8) at fcall.c:562
#12 0x00000001023074db in zim_Phalcon_Mvc_View_Engine_Volt_Compiler_expression (ht=1, return_value=0x100aef778, return_value_ptr=0x7fff5fbfc788, this_ptr=0x100aed8f8, return_value_used=1) at compiler.c:1725
#13 0x0000000102168861 in phalcon_execute_internal (execute_data_ptr=0x7fff5fbfc2c0, fci=0x7fff5fbfc418, return_value_used=1) at phalcon.c:53
#14 0x0000000100d73d20 in xdebug_execute_internal ()
#15 0x00000001001b1dc7 in zend_call_function ()
#16 0x000000010216d4c4 in phalcon_call_user_function (object_pp=0x7fff5fbfc628, obj_ce=0x102d2ca60, type=phalcon_fcall_method, function_name=0x7fff5fbfc5c0, retval_ptr_ptr=0x7fff5fbfc788, param_count=1, params=0x7fff5fbfc750) at fcall.c:429
#17 0x000000010216dc60 in phalcon_call_class_method_aparams (return_value_ptr=0x7fff5fbfc788, ce=0x102d2ca60, type=phalcon_fcall_method, object=0x100aed8f8, method_name=0x10252a766 "expression", method_len=10, param_count=1, params=0x7fff5fbfc750) at fcall.c:562
#18 0x000000010230e21f in zim_Phalcon_Mvc_View_Engine_Volt_Compiler_compileEcho (ht=1, return_value=0x100aef670, return_value_ptr=0x7fff5fbfd170, this_ptr=0x100aed8f8, return_value_used=1) at compiler.c:2456
#19 0x0000000102168861 in phalcon_execute_internal (execute_data_ptr=0x7fff5fbfc990, fci=0x7fff5fbfcae8, return_value_used=1) at phalcon.c:53
#20 0x0000000100d73d20 in xdebug_execute_internal ()
#21 0x00000001001b1dc7 in zend_call_function ()
#22 0x000000010216d4c4 in phalcon_call_user_function (object_pp=0x7fff5fbfccf8, obj_ce=0x102d2ca60, type=phalcon_fcall_method, function_name=0x7fff5fbfcc90, retval_ptr_ptr=0x7fff5fbfd170, param_count=1, params=0x7fff5fbfd060) at fcall.c:429
#23 0x000000010216dc60 in phalcon_call_class_method_aparams (return_value_ptr=0x7fff5fbfd170, ce=0x102d2ca60, type=phalcon_fcall_method, object=0x100aed8f8, method_name=0x10252bc52 "compileecho", method_len=11, param_count=1, params=0x7fff5fbfd060) at fcall.c:562
#24 0x0000000102313453 in zim_Phalcon_Mvc_View_Engine_Volt_Compiler__statementList (ht=2, return_value=0x100af0360, return_value_ptr=0x7fff5fbfde40, this_ptr=0x100aed8f8, return_value_used=1) at compiler.c:3082
#25 0x0000000102168861 in phalcon_execute_internal (execute_data_ptr=0x7fff5fbfd900, fci=0x7fff5fbfda58, return_value_used=1) at phalcon.c:53
#26 0x0000000100d73d20 in xdebug_execute_internal ()
#27 0x00000001001b1dc7 in zend_call_function ()
#28 0x000000010216d4c4 in phalcon_call_user_function (object_pp=0x7fff5fbfdc68, obj_ce=0x102d2ca60, type=phalcon_fcall_method, function_name=0x7fff5fbfdc00, retval_ptr_ptr=0x7fff5fbfde40, param_count=2, params=0x7fff5fbfddd0) at fcall.c:429
#29 0x000000010216dc60 in phalcon_call_class_method_aparams (return_value_ptr=0x7fff5fbfde40, ce=0x102d2ca60, type=phalcon_fcall_method, object=0x100aed8f8, method_name=0x10252b3d2 "_statementlist", method_len=14, param_count=2, params=0x7fff5fbfddd0) at fcall.c:562
#30 0x0000000102316054 in zim_Phalcon_Mvc_View_Engine_Volt_Compiler__compileSource (ht=2, return_value=0x100aef108, return_value_ptr=0x100ab40d8, this_ptr=0x100aed8f8, return_value_used=1) at compiler.c:3321
#31 0x0000000102168861 in phalcon_execute_internal (execute_data_ptr=0x7fff5fbfe1b0, fci=0x7fff5fbfe308, return_value_used=1) at phalcon.c:53
#32 0x0000000100d73d20 in xdebug_execute_internal ()
#33 0x00000001001b1dc7 in zend_call_function ()
#34 0x000000010216d4c4 in phalcon_call_user_function (object_pp=0x7fff5fbfe518, obj_ce=0x102d2ca60, type=phalcon_fcall_method, function_name=0x7fff5fbfe4b0, retval_ptr_ptr=0x100ab40d8, param_count=2, params=0x7fff5fbfe6a8) at fcall.c:429
#35 0x000000010216dc60 in phalcon_call_class_method_aparams (return_value_ptr=0x100ab40d8, ce=0x102d2ca60, type=phalcon_fcall_method, object=0x100aed8f8, method_name=0x10252bdca "_compilesource", method_len=14, param_count=2, params=0x7fff5fbfe6a8) at fcall.c:562
#36 0x000000010230a6db in phalcon_return_call_class_method (return_value=0x100aef288, return_value_ptr=0x100ab40d8, ce=0x102d2ca60, type=phalcon_fcall_method, object=0x100aed8f8, method_name=0x10252bdca "_compilesource", method_len=14, param_count=2, params=0x7fff5fbfe6a8) at fcall.h:592
#37 0x00000001023173d0 in zim_Phalcon_Mvc_View_Engine_Volt_Compiler_compileString (ht=1, return_value=0x100aef288, return_value_ptr=0x100ab40d8, this_ptr=0x100aed8f8, return_value_used=1) at compiler.c:3456
#38 0x00000001021688b9 in phalcon_execute_internal (execute_data_ptr=0x100ab4570, fci=0x0, return_value_used=1) at phalcon.c:57
#39 0x0000000100d73d20 in xdebug_execute_internal ()
#40 0x0000000100224fe4 in zend_do_fcall_common_helper_SPEC ()
#41 0x00000001001e0e02 in execute_ex ()
#42 0x0000000100d73a64 in xdebug_execute_ex ()
#43 0x00000001001bdf44 in zend_execute_scripts ()
#44 0x000000010016aca7 in php_execute_script ()
#45 0x0000000100242323 in do_cli ()
#46 0x00000001002417ba in main ()
(gdb) |
OK, it's an issue related to xdebug. I disabled it and the everything works: string(34) "<?php echo ucwords('it-works'); ?>"
string(46) "<?php echo Phalcon\Text::upper('it-works'); ?>"
string(42) "<?php echo ucwords('it-does-not-work'); ?>"
string(56) "<?php echo str_replace('-', ' ', 'it-does-not-work'); ?>"
Program exited normally. Now I'm asking, why this happen? It's a Phalcon bug or an xdebug issue? It seems that xdebug is trying to read a memory location that can't be read. |
It could be a phalcon stack trace that xdebug is trying to inspect or some leak from phalcon that affect xdebug. I had some issues too with xdebug, disabled it and had no issue since that. Also, see #2239. |
Added a pull request on xdebug to fix the problem: xdebug/xdebug#120 |
This code used to work in the past, but I have tried to downgrade with no success. After many tests I figured out that any calls to
compileString()
returns FALSE:should return:
instead it returns:
// false
Since the compileString() returns FALSE, I'm not able to get a valid response, unless I don't use a custom filter. In case of a custom filter in fact I get a "no data received" Chrome blank page.
This is the service:
This instead is the template when I'm using the filter:
I can only use a built-in filter, because any custom filter produces the issue described.
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: