pbiggar / phc

A compiler for PHP
132 stars 37 forks source link

$php_errormsg is not working inside a function #123

Closed pbiggar closed 9 years ago

pbiggar commented 9 years ago
Hello

Here is a script to reproduce the bug :

<?php
function show_error()
{
        @strpos();
        $error_message = $php_errormsg;
        echo "inside the function : $error_message \n";
}
show_error();
?>

With the php cli it works, but the same script compiled with phc does not
works.

What steps will reproduce the problem?
1. I put what I do on a attach file

What version of the product are you using? On what operating system?
Slackware 13.0 x86 32bits
PHP 5.2.11 and 5.2.10
PHC 0.2.0.3

Thanks

Original issue reported on code.google.com by jeanroch.rossi on 2009-10-05 12:24:07


pbiggar commented 9 years ago
Thanks for the report. Try the following patch:

Index: src/optimize/Prune_symbol_table.cpp
===================================================================
--- src/optimize/Prune_symbol_table.cpp (revision 3300)
+++ src/optimize/Prune_symbol_table.cpp (working copy)
@@ -111,6 +111,11 @@
                // record variable names for removing globals
                if (record_globals)
                        (*vars)[*in->value] = true;
+
+               // Dont do this optimization in the presence of php_errormsg.
+               // There are much better ways of doing this, but this is the simplest.
+               if (*in->value == "php_errormsg")
+                       prune = false;
        }

        void post_variable_variable (Variable_variable* in)

It seems to work for me, but I'm running more tests now to make sure it doesnt break
anything.

Original issue reported on code.google.com by paul.biggar on 2009-10-05 13:33:16

pbiggar commented 9 years ago
Thanks,
yes it is working for me too :)
and also in a function call by another function

Original issue reported on code.google.com by jeanroch.rossi on 2009-10-05 16:14:51

pbiggar commented 9 years ago
OK, fix committed in revision 3301.

Thanks for the report and verification.

Original issue reported on code.google.com by paul.biggar on 2009-10-05 17:33:10