Hello. There is a code

class class1{ public $name='string'; } class class2 extends class1{ function __construct(){ self::$name ='class2'; /*Вот где-то тут проблема*/ echo $name; } } $one = new first(); 

How to create a new Class2 object and reassign the variable of the parent class Class1 and display its value?

So that the string "class2" is displayed as a result?

    1 answer 1

    I did not quite understand what the class first in your example, but if you omit it, the problem is that you are trying to access the property as static, although it is not so, try the following option:

     class class1{ public $name='string'; } class class2 extends class1{ function __construct(){ $this->name = 'class2'; // Правильное обращение к свойству класса. echo $this->name; } } 

    I also advise you to read the Introduction to the PLO in order to understand what is happening here at all.

    • one
      Yes, be sure to read, thank you)) - rozbyn