想知道这在 PHP Land 中是否可行:
假设我有一堂课如下:
class myClass{
var $myVar;
...
myMethod(){
$this->myVar = 10;
}
}
和另一个类:
class anotherClass {
...
addFive(){
$this->myVar += 5;
}
}
'anotherClass' 有 3500 行长,我只想在 myClass 中使用单个 'addFive' 方法。
- 有没有办法可以导入函数并能够在我的类中调用它,并且 $this 会引用 myClass 对象?
- 这是好/坏的做法吗?
- (可选)这在 Python 中是如何工作的?(只是好奇,因为我开始学习 Python)