+ 1
What's my mistake?
What am I doing wrong? https://code.sololearn.com/wv2Iz0cxLC85/?ref=app
4 Respuestas
+ 3
private variable of abstract class can't be access in subclass. This was your first mistake.
You can access only public and protected.
+ 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();
?>
+ 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.
0
Ah okay thanks
forgot about it