pear-core: Remove calls with incompatible Context

raw

1-test.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/**
 * http://pear.php.net/bugs/bug.php?id=20488
 * https://github.com/php/php-src/pull/1026
 * https://wiki.php.net/rfc/incompat_ctx
 */
class A
{
    function bNon()
    {
        //i'm not interested in this
        echo "A::bNon\n";
    }
 
    static function cStat()
    {
        if (isset($this)) {
            //static method has been called non-statically
            //$this is instance of A
            echo '$a->cStat' . "\n";
        } else {
            //static method has been called statically
            echo "A::cStat\n";
        }
    }
 
    static function dStaticVarHack()
    {
        $his = 'this';
        if (isset($$his)) {
            //static method has been called non-statically
            //$this is instance of A
            echo '$a->dStaticVarHack' . "\n";
        } else {
            //static method has been called statically
            echo "A::dStaticVarHack\n";
        }
    }
 
    function eVarHack()
    {
        $his = 'this';
        if (isset($$his)) {
            //method has been called non-statically
            //$this is instance of A
            echo '$a->eVarHack' . "\n";
        } else {
            //method has been called statically
            echo "A::eVarHack\n";
        }
    }
}
 
//this should fail, that's fine
A::bNon();
 
//but this should work both:
A::cStat();
$a = new A();
$a->cStat();
 
//but this should work both:
A::dStaticVarHack();
$a = new A();
$a->dStaticVarHack();
 
A::eVarHack();
$a = new A();
$a->eVarHack();
 
?>
 
raw

2-test-output.txt

$ php phork0.php 
A::bNon
A::cStat
A::cStat
A::dStaticVarHack
A::dStaticVarHack
A::eVarHack
$a->eVarHack

$ php -derror_reporting=32767 phork0.php 
PHP Strict standards:  Non-static method A::bNon() should not be called statically in /home/cweiske/php/165/phork0.php on line 54
PHP Stack trace:
PHP   1. {main}() /home/cweiske/php/165/phork0.php:0

Strict standards: Non-static method A::bNon() should not be called statically in /home/cweiske/php/165/phork0.php on line 54

Call Stack:
    0.0001     240320   1. {main}() /home/cweiske/php/165/phork0.php:0

A::bNon
A::cStat
A::cStat
A::dStaticVarHack
A::dStaticVarHack
PHP Strict standards:  Non-static method A::eVarHack() should not be called statically in /home/cweiske/php/165/phork0.php on line 66
PHP Stack trace:
PHP   1. {main}() /home/cweiske/php/165/phork0.php:0

Strict standards: Non-static method A::eVarHack() should not be called statically in /home/cweiske/php/165/phork0.php on line 66

Call Stack:
    0.0001     240320   1. {main}() /home/cweiske/php/165/phork0.php:0

A::eVarHack
$a->eVarHack
raw

3-magic-call.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
class A
{
    static function _b($obj, $hello, $world)
    {
        if (isset($obj)) {
            echo "non-static: $hello $world\n";
        } else {
            echo "static: $hello $world\n";
        }
    }
 
    function __call($method, $args)
    {
        if ($method == 'b') {
            call_user_func_array(
                array($this, '_' . $method),
                array_merge(array($this), $args)
            );
        }
    }
 
    static function __callStatic($method, $args)
    {
        if ($method == 'b') {
            call_user_func_array(
                array(get_class(), '_' . $method),
                array_merge(array(null), $args)
            );
        }
    }
}
A::b('hello', 'world');
$a = new A();
$a->b('hello', 'world');
?>
raw

4-magic-call-output.txt

static: hello world
non-static: hello world
Christian Weiske Christian Weiske
owner

History