我迟到了,刚刚开始学习OOP PHP。 我希望我可以按照以下方针做点什么。
class Thingy {
public $uuid;
function __construct() {
$this->uuid = 'abc123';
}
function AddHandle() {
$handle = new Handle();
return $handle;
}
...
}
class Handle {
public $parent;
function __contruct () {
$this->parent = **UUID OF THE OBJECT THAT CREATED A NEW INSTANCE**;
}
...
}
这样我就不需要将调用对象的UUID传递给它创建的对象。 这是一个愚蠢的想法吗? 我应该总是传递调用对象的UUID吗?
function AddHandle() {
$handle = new Handle($this->uuid);
return $handle;
}
然后通过Handle的构造函数传递$ this-> uuid?
就像我刚说的那样。刚开始 如果我回答了我自己的问题,那很好,请告诉我。 如果没有人可以帮助我,或指出我正确的方向? 非常感谢。