Answer the question
In order to leave comments, you need to log in
Is declaring a property as an object a mistake?
Hello, I can't figure out why I can't access the array.
I decided to declare the property as an object and work through it
public $shop;
public function __construct(){
$this->shop = new Shop;
}
#1.Showing shop basket for user
public function showBasket(){
if(!empty($this->array)){
foreach($this->array as $key => $value){
$this->shop->render($key);
echo "<br><br>";
}
}
}
Answer the question
In order to leave comments, you need to log in
That is, do you sincerely believe that if you write
$this->shop = new Shop;
this variable in some place in the code, it will immediately have access to all objects of the Shop class ever created in the code?
And your example can be simplified to this
class Person {
public function __construct(){
$this->name = '';
}
public function showname(){
echo $this->name;
}
}
$name = "Вася";
$person = new Person;
$person->showname();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question