Skip to content

Instantly share code, notes, and snippets.

@mentisy
Created March 21, 2023 23:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mentisy/6f3f8872b9a529c86b1e3eb80c9fc900 to your computer and use it in GitHub Desktop.
Save mentisy/6f3f8872b9a529c86b1e3eb80c9fc900 to your computer and use it in GitHub Desktop.
Eksempler på OOP i PHP for å sammenligne med Cue Visual Basic
<?php
declare(strict_types=1);
namespace App;
/**
* Cell class
*
* Abstract class for inheritance
*/
abstract class Cell
{
/**
* Cell ID
*/
protected const ID = 0;
/**
* Set intercom alarm status
*
* @param bool $status Status. True for start and false for stop
* @return void
*/
public function ContrMaster_funcCell_eIntercomAlarm(bool $status)
{
if ($status) {
$this->intercomAlarmStart();
} else {
$this->intercomAlarmStop();
}
}
/**
* Start intercom alert
*
* @return void
*/
public function intercomAlarmStart()
{
echo "intercom alert start for cell " . static::ID . "\n";
}
/**
* Stop intercom alert
*
* @return void
*/
public function intercomAlarmStop()
{
echo "intercom alert stop for cell " . static::ID . "\n";
}
}
<?php
declare(strict_types=1);
namespace App;
class CellFour extends Cell
{
/**
* Cell ID
*/
protected const ID = 4;
}
<?php
declare(strict_types=1);
namespace App;
class CellOne extends Cell
{
/**
* Cell ID
*/
protected const ID = 1;
}
<?php
declare(strict_types=1);
namespace App;
class CellThree extends Cell
{
/**
* Cell ID
*/
protected const ID = 3;
/**
* @inheritDoc
*/
public function intercomAlarmStart()
{
parent::intercomAlarmStart();
echo "Overriden extra message for cell three\n";
}
}
<?php
declare(strict_types=1);
namespace App;
class CellTwo extends Cell
{
/**
* Cell ID
*/
protected const ID = 2;
/**
* Change state of water for toilet
*
* @param int $state 0: Open, 1: Close, 2: Toggle
* @return void
*/
public function SetWaterWC(int $state)
{
switch ($state) {
case 0: echo "open";
case 1: echo "close";
case 2: echo "toggle?";
}
}
}
<?php
require 'vendor/autoload.php';
use App\CellFour;
use App\CellOne;
use App\CellThree;
use App\CellTwo;
$cellOne = new CellOne();
$cellOne->intercomAlarmStart();
$cellTwo = new CellTwo();
$cellTwo->intercomAlarmStart();
$cellThree = new CellThree();
$cellThree->intercomAlarmStart();
$cellFour = new CellFour();
$cellFour->intercomAlarmStart();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment