Skip to content

parent::$foo with parent class after child class #8

Closed
@nikic

Description

@nikic

Currently the implementation needs the ->parent CE of the active_class_entry to implement parent::$foo accesses. Normally this information is not available until runtime. To avoid it the implementation scans the opcodes for the ZEND_CLASS_FETCH instruction, extracts its name and looks it up in the class entry table.

This procedure fails if the extended class is only defined after the child class, as the following example shows:

<?php

class A extends B {
    public $foo {
        get { return 'parent::' . parent::$foo; }
    }
}

class B {
    public $foo {
        get { return 'foo'; }
    }
}

$a = new A;
var_dump($a->foo);

In this case an error is thrown:

 Fatal error: Access to undeclared static property: B::$foo in /home/nikic/dev/php-src/test.php on line 5

Even though static accessors won't be supported, this still has to be solved, because parent::$foo is used for normal properties as well.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions