Bug #75933 [Opn->Fbk]: call_user_func_array does not resolve parent for instances

From: Date: Thu, 08 Feb 2018 00:23:47 +0000
Subject: Bug #75933 [Opn->Fbk]: call_user_func_array does not resolve parent for instances
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-213856@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75933&edit=1 ID: 75933 Updated by: daverandom@php.net Reported by: jason at papertower dot com Summary: call_user_func_array does not resolve parent for instances -Status: Open +Status: Feedback Type: Bug Package: Class/Object related Operating System: MacOS 10.13.3 PHP Version: 7.1.14 Block user comment: N Private report: N New Comment: Not enough information was provided for us to be able to handle this bug. Please re-read the instructions at http://bugs.php.net/how-to-report.php If you can provide more information, feel free to add it to this bug and change the status back to "Open". Thank you for your interest in PHP. Once I fixed the two unrelated errors in your example (a class cannot be named "Parent" and call_user_func_array requires a second argument), this seems to work without issue: https://3v4l.org/huQ0d Can you create a script which directly reproduces the error you encountered? Thanks Previous Comments: ------------------------------------------------------------------------ [2018-02-08 00:14:24] jason at papertower dot com Fixed typo in summary ------------------------------------------------------------------------ [2018-02-08 00:12:11] jason at papertower dot com Description: ------------ When working within a child class, attempting to call a parent instance method using call_user_func_array is impossible. The function will always interpret the callable as a static method, rather than an instance. I apologize if this is in the wrong place or if not enough information was provided. It seems like a simple, reproducible bug. It makes sense, as I'm not sure how the function would discern the parent. Perhaps there needs to be an explicit equivalent of $this but for the parent? Test script: --------------- class Parent { function A() {} } class Child extends Parent { function B() { call_user_func_array('parent::A'); } } $child = new Child(); $child->B(); Expected result: ---------------- I would expect the code to be the equivalent of running parent::A() within the method, resolving based on context whether the parent is an instance or class. Actual result: -------------- An error is throwing saying the callable is not a valid callback as a non-static method was expected, and an instance method should not be called statically. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75933&edit=1

« previous php.bugs (#213856) next »