|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #71851 Method aliases exhibit unexpected inheritance behavior
Submitted: 2016-03-18 07:35 UTC Modified: 2020-09-18 10:21 UTC
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: tom at theanalogguy dot be Assigned:
Status: Verified Package: Scripting Engine problem
PHP Version: Irrelevant OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2016-03-18 07:35 UTC] tom at theanalogguy dot be
When extending SplObjectObserver for a custom implementation of ::attach(), any calls to ::offsetSet() are forwarded to the SplObjectObserver::attach() instead of the custom implementation in the child class.

Test script:

This appears to affect all versions between 5.5.0 and 7.0.4

Test script:
class Test extends \SplObjectStorage
     * {@inheritDoc}
    public function attach($object, $data = null)
        throw new \RuntimeException('this is a test');

$instance = new Test;
$object = new \stdClass;
$data = ['foo' => 'bar'];

$instance[$object] = $data;

Expected result:
A RuntimeException being thrown.

Actual result:
No RuntimeException was thrown.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-03-18 21:08 UTC] jachimcoudenys at gmail dot com
I've started to write a test case:
 [2020-09-18 10:21 UTC]
-Summary: SplObjectStorage incorrectly aliases offsetSet +Summary: Method aliases exhibit unexpected inheritance behavior -Status: Open +Status: Verified -Type: Bug +Type: Documentation Problem -Package: SPL related +Package: Scripting Engine problem
 [2020-09-18 10:21 UTC]
This is not particularly related to SplObjectStorage::offsetSet(),
but rather a general property of method aliases wrt. inheritance.
Method aliases are implemented by adding a respective entry to the
class_entry's function_table, which shares the function_entry with
the aliased method.  However, there is no special support
regarding inheritance; the alias and the aliased method can be
overridden indepently.

In hindsight, it might not have been the best idea to even support
such aliases, but fixing their inheritance behavior would be a BC
break, so I think we should treat this as a documentation problem.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 12 21:01:30 2024 UTC