Skip to content

Instantly share code, notes, and snippets.

@yuyu-TZ321
Last active August 19, 2017 13:59
Show Gist options
  • Save yuyu-TZ321/a36e5740bf6af090bea8ded1de5d455d to your computer and use it in GitHub Desktop.
Save yuyu-TZ321/a36e5740bf6af090bea8ded1de5d455d to your computer and use it in GitHub Desktop.
<?php
interface Info
{
public function channelMessage();
}
abstract class Live
{
const RANGE = 10;
protected $point = 0;
abstract protected function loginchat();
public function onLive()
{
$this->point += self::RANGE * 10;
echo $this->point . "\r\n";
}
public final function offLive()
{
$this->point += self::RANGE * 1;
echo $this->point . "\r\n";
}
}
class Twitch extends Live implements Info
{
private $channelname;
public function __construct($name)
{
$this->channelname = $name;
echo "Welcome to " . $this->channelname . " channel\r\n";
}
protected function loginChat()
{
echo "Log in " . $this->channelname . " chat\r\n";
}
public function channelMessage()
{
$this->loginChat();
echo "This is " . $this->channelname . " \r\n";
}
public static function liveType()
{
echo "TWITCH \r\n";
}
}
class FbLive extends Live implements Info
{
//計算觀看人數
private $num = 0;
public function __construct()
{
$this->num++;
}
protected function loginChat()
{
echo "welcome fb live chat\r\n";
}
public function channelMessage()
{
$this->loginChat();
echo "This num " . $this->num . " \r\n";
}
public static function liveType()
{
echo "FaceBook \r\n";
}
}
$fbLive = new FbLive();
$fbLive->onLive();
$fbLive->channelMessage();
$fbLive->offLive();
fbLive::liveType();
$twitch = new Twitch('yuyu0321');
$twitch->onLive();
$twitch->channelMessage();
$twitch->offLive();
Twitch::liveType();
@dinos80152
Copy link

dinos80152 commented Aug 13, 2017

  • class name 要大寫
class live
class Live
  • const 小寫
CONST RANGE = 10;
const RANGE = 10;
  • 這個不需要
?>

@dinos80152
Copy link

  • 所有的 method 都要有 public, protected, private,包含 construct
  • 換行也可以使用 PHP_EOL
  • method 間隔一行, properties 間不用
  • properties 和 methods 間隔一行
  • . 前後要空隔
    echo $this->point."\r\n";
    echo $this->point . "\r\n";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment