In my code, it was because I had not defined currentDomain and basePath as public outside of __construct()
xxxxxxxxxx
namespace Admin;
class Admin{
// I had not written these two variables
public $currentDomain;
public $basePath;
function __construct(){
$this->currentDomain = CURRENT_DOMAIN;
$this->basePath = BASE_PATH;
}
I hope my example was useful for you, I wish for better codes.
I am not an English speaker, I hope I was able to convey my meaning
in my case : i add this #[AllowDynamicProperties] before the class and fixed
xxxxxxxxxx
#[AllowDynamicProperties]
class User{
// in my case User class is empty
}
interface Builder{
public function reset();
public function build();
public function setName($name);
public function setFamily($family);
}
class UserBuilder implements Builder{
private $user;
public function __construct(){
$this->reset();
}
public function reset(){
$this->user = new User();
}
public function build(){
return $this->user;
}
public function setName($name){
$this->user->name = $name;
return $this;
}
public function setFamily($family){
$this->user->family = $family;
return $this;
}
}
$user = new UserBuilder();
$user->setName('Mohammad')
->setFamily('Family')
var_dump($user);
I hope my example was useful for you, I wish for better codes.
I am not an English speaker, I hope I was able to convey my meaning