【发布时间】:2018-10-27 15:32:59
【问题描述】:
是否可以在覆盖父类方法的同时对其进行扩展?例如:
class Foo {
public function edit() {
$item = [1,2];
return compact($item);
}
}
class Bar extends Foo {
public function edit() {
// !!! Here, is there any way I could import $item from parent class Foo?
$item2 = [3,4]; //Here, I added (extended the method with) some more variables
return compact($item, $item2); // Here I override the return of the parent method.
}
}
问题是我无法以任何方式编辑 Foo 类,因为它是一个供应商包。
我不想编辑我需要扩展它们的供应商方法(向他们的return 函数添加更多内容)
【问题讨论】:
-
你为什么使用
compact()? -
没有理由,只是举例。类似于
return view('view-file', compact($item))
标签: php function class methods