'How to bring in the proper form? php basic oop
the problem is this, I'm doing a task to understand the syntax of php + basic oop syntax. The meaning of the task is to create a developer class that implements the primate interface and inherits the abstract developer class, it also inherits the plankton trait that can drink coffee. Here is my code
declare(strict_types=1);
interface Primat {
public function eat(bool $e);
public function drink(bool $d);
}
trait ofPlank{
function cofeeTime($cof){ echo 'drink cofee ';}
}
abstract class Human{
public string $name;
abstract public function work(string $work);
}
class Dev extends Human implements primat{
use ofPlank;
public $rank = array(
1=>'junior',
2=>'middle',
3=>'senior',
4=>'lead'
);
public int $rankState = 0;
public function __construct(int $currentRank)
{
$this->rankState = $currentRank;
}
public function show()
{
echo $this->rank[$this->rankState];
}
public function Up()
{
$this->rankState++;
}
public function Down()
{
$this->rankState--;
}
public function eat( $e)
{
if ($e ==1){
echo 'eat';}
else {
echo 'hungry';
}
// TODO: Implement eat() method.
}
public function drink($d)
{
if ($d ==1){
echo 'drink';}
else {
echo 'need water';
} ; // TODO: Implement drink() method.
}
use ofPlank;
public function work($work)
{
$work = 'go to work';
// TODO: Implement work() method.
}
} echo 'backend promotion from';
$backend = new Dev(1,);
echo $backend->show()."\n";
$backend->Up();
echo 'to ';
echo $backend->show()."\n";
echo '|backend need eat->';
$backend->eat($e=1);
//var_dump($backend);
echo '|ofplank ';
$backend->cofeeTime(cof );
?>
<br><?php
echo 'frontend lvl ';
$frontend = new dev(1,);
echo $frontend->show()."\n";
echo '|frontend need water->';
$backend->drink($d=2);
?>
<br>
<br>
<br>
<br>
<br>
I would like to know how this code can be improved? Does this code fit the definition of the simplest OOP? what did done wrong on psr 1-2? And finally, how can the work method accept a work instance parameter? Thanks in advance to everyone who gives me their time!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
