# Nasty Parser Bug

- Thread: https://externals.io/message/3158
- Original archive: https://news-web.php.net/php.internals/3158
- Started by Sterling Hughes on 2003-07-02T04:34:52+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #3158 — Sterling Hughes — 2003-07-02T04:34:52+00:00

URL: https://externals.io/message/3158#3158

Hey,

Bug 24441 (http://bugs.php.net/bug.php?id=24441), displays the following
problem:

<?php
class test {
        var $filter = 'hello';
        var $array = array('hello', 'hello world', 'hey there');
 
        function test() {
                array_filter($this->array, array($this, 'filter'));
        }
 
        function filter ($value) {
                return preg_match("/{$this->filter}/i", $value);
        }
}
$t = new test;
var_dump($t->filter('hello world'));
?>

That script (also attached), will give an error:

Fatal error: Using $this when not in object context in
/data/home/sterling/work/os/php/php-src/arraybug.php on line 11

If you comment out the test() function declaration, everything will work
as expected.  

-Sterling
-- 
"First they ignore you, then they laugh at you,  
 then they fight you, then you win."  
    - Gandhi

---

## #3165 — Sterling Hughes — 2003-07-02T14:04:29+00:00

URL: https://externals.io/message/3158#3165 · In reply to: #3164

> 
> [...]
> > […]
>   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>   Changing this line to:
>     var_dump(call_user_func(array($t, 'filter'), 'hello world'));
> 
>   or even
>     $t= new Reflection_Method('test', 'filter');
>     var_dump($t->invoke(new test(), 'hello world'));
> 
>   yields the same bug.
> 
> ZE1 outputs "int(1)". ZE2 does so, too, if I rename "test" to anything
> else (except "__construct", which causes the same problem).
> 
> The same problem arises for other array functions such as usort,
> array_map etc., but _not_ for call_user_func(_array).
> 
> After short investigation it looks like all of these use
> fast_call_user_function() but do not pass an object_pp. Either this
> should be patched in ext/standard/array.c or fast_call_user_function
> shoud check for the callback being an array($obj, $func) / array($class,
> $func) *even* when a function pointer is passed.

Then why would it work if test() is undefined?  Further, why would it
work when no array functions are used (as with my original example).  I
think you might be right that this is a separate bug, but its certainly
not the same bug that I'm talking about.

-Sterling

> 
> - Timm
-- 
"Nothing is particularly hard if you divide it into small jobs." 
    - Henry Ford

---

## #3164 — Timm Friebe — 2003-07-02T14:11:47+00:00

URL: https://externals.io/message/3158#3164 · In reply to: #3158

[...]
> $t = new test;
> var_dump($t->filter('hello world'));
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  Changing this line to:
    var_dump(call_user_func(array($t, 'filter'), 'hello world'));

  or even
    $t= new Reflection_Method('test', 'filter');
    var_dump($t->invoke(new test(), 'hello world'));

  yields the same bug.

ZE1 outputs "int(1)". ZE2 does so, too, if I rename "test" to anything
else (except "__construct", which causes the same problem).

The same problem arises for other array functions such as usort,
array_map etc., but _not_ for call_user_func(_array).

After short investigation it looks like all of these use
fast_call_user_function() but do not pass an object_pp. Either this
should be patched in ext/standard/array.c or fast_call_user_function
shoud check for the callback being an array($obj, $func) / array($class,
$func) *even* when a function pointer is passed.

- Timm
