<?php
abstract class file
{
private $pid;
private $uid;
public function __construct($pid,$uid)
{
$this->pid = $pid;
$this->uid = $uid;
}
public function valid()
{
if($_SESSION['level']<$this->pid)
{
return true;
}
else
return false;
}
public function allow()
{
return "This is all right!";
}
}
?>
<?php
// put your code here
include("../file.php");
session_start();
class android extends file
{
public function __construct($pid,$uid)
{
parent::__construct($pid, $uid);
}
}
$uid = $_SESSION['id'];
$pa = new android(1,$uid);
if($pa->valid())
echo $pa->allow();
else
echo "<h1>No permission<h1>"
?>
The above class is android class and the one above that is file.. Now when the android extends(inherits) the file class, it means it has all the methods. But when I try to run the program, it says undefined variable android::allow()
I dont understand because I have defined the allow() function in the file class and so the android class should inherit the method as well.
please help.. Thanks in advance.
According to http://www.php.net/manual/en/language.oop5.abstract.php ,
If your file class doesn’t have any abstract method, don’t bother declaring it as abstract, otherwise avoid calling the constructor 😉