Bug->Doc #71851 [Opn->Ver]: Method aliases exhibit unexpected inheritance behavior

From: Date: Fri, 18 Sep 2020 10:21:53 +0000
Subject: Bug->Doc #71851 [Opn->Ver]: Method aliases exhibit unexpected inheritance behavior
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-17895@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71851&edit=1

 ID:                 71851
 Updated by:         cmb@php.net
 Reported by:        tom at theanalogguy dot be
-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
 Operating System:   Linux
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2016-03-18 21:08:28] jachimcoudenys at gmail dot com

I've started to write a test case: https://github.com/coudenysj/php-src/commit/22c6e1daf516dead9f70dea0722f7e3aec69df0d

------------------------------------------------------------------------
[2016-03-18 07:35:13] tom at theanalogguy dot be

Description:
------------
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: https://3v4l.org/mXdWO

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.


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=71851&edit=1


Thread (1 message)

  • cmb@php.net
  • Unknown Message
    • cmb@php.net
« previous php.doc.bugs (#17895) next »