+ 1

What's my mistake?

What am I doing wrong? https://code.sololearn.com/wv2Iz0cxLC85/?ref=app

17th Oct 2019, 8:54 PM
Matthias Hoffmann
Matthias Hoffmann - avatar
4 Answers
+ 3
private variable of abstract class can't be access in subclass. This was your first mistake. You can access only public and protected.
18th Oct 2019, 1:01 PM
A͢J
A͢J - avatar
+ 1
Check this what I did <?php abstract class A { public static $var = 2; } class B extends A { public function __construct(){ $var = self::$var; } public function fun1(){ echo self::$var; } } $obj = new B; $obj->fun1(); ?>
18th Oct 2019, 12:44 PM
A͢J
A͢J - avatar
+ 1
Yeah. That what I've tried first but for some reason it didn't worked so I tried the code that I've posted but it also didn't worked. Now your one is working so I think I've made a mistake in my first attempt.
18th Oct 2019, 12:53 PM
Matthias Hoffmann
Matthias Hoffmann - avatar
0
Ah okay thanks forgot about it
18th Oct 2019, 1:23 PM
Matthias Hoffmann
Matthias Hoffmann - avatar