コード例 #1
0
ファイル: index.php プロジェクト: asaoushine/code_igniter_dev
<!DOCTYPE html>
<html lang="ja">
<head>
	<meta charaset="utf-8">
	<title>自分で設定したindexが表示されるかのテスト</title>
</head>
<body>
	<p>ここがテストの部分です</p>
	<?php 
class Television
{
    public $channelNo;
    function dispChannel()
    {
        print "現在のチャンネルは... " . $this->channelNo . " です!";
    }
}
$hoge = new Television();
$hoge->channelNo = 8;
$hoge->dispChannel();
?>
</body>
</html>
コード例 #2
0
class StoreManager {
  private $_productList = array();

  public function addProduct( Sellable $product ) {
    $this->_productList[] = $product;
  }

  public function stockUp() {
    foreach ( $this->_productList as $product ) {
      $product->addStock( 100 );
    }
  }
}

$tv = new Television;
$tv->setScreenSize( 42 );
$ball = new TennisBall;
$ball->setColor( "yellow" );
$manager = new StoreManager();
$manager->addProduct( $tv );
$manager->addProduct( $ball );
$manager->stockUp();
echo "<p>There are ". $tv->getStockLevel() . " " . $tv->getScreenSize();
echo "-inch televisions and " . $ball->getStockLevel() . " " . $ball->getColor();
echo " tennis balls in stock.</p>";
echo "<p>Selling a television...</p>";
$tv->sellItem();
echo "<p>Selling two tennis balls...</p>";
$ball->sellItem();
$ball->sellItem();
コード例 #3
0
    }
}
class Clothing extends Product
{
    protected $size;
    protected $type;
    protected $color;
    protected $gender;
    public function __construct($name, $brand, $price, $type, $size, $color, $gender)
    {
        parent::__construct($name, $brand, $price);
        $this->size = $size;
        $this->type = $type;
        $this->color = $color;
        $this->gender = $gender;
    }
    public function provideDescriptionForProductType()
    {
        return "This is an article of clothing. It is a " . $this->brand . " " . $this->color . " " . $this->gender . " " . $this->type . " of size " . $this->size . " it costs " . $this->price;
    }
}
$buttonDownShirt = new Clothing("Button Down Shirt", "J Peterman", 29.88, "shirt", "medium", "Eye-piercingly bright red", "Male");
$kramericaTV = new Television("Giant TV", "Kramerica", 3900.9, "LED", "100in");
echo $buttonDownShirt->provideDescription();
echo "</br>";
echo $kramericaTV->provideDescription();
?>
        
    </p>
  </body>
</html>