PHP Based on PHP 5 http www php
PHPの基礎と開発手法 Based on PHP 5 http: //www. php. net/ Yuki Matsukura matsu@ht. sfc. keio. ac. jp 9/15/2021
PHPの動かし方 o <? php で始まり o ? > で終わる o 拡張子 n n . php o PHPスクリプト. phps o PHPソース <html> <h 1>Say something</h 1> <? php print “hello”; ? > </html>
PHPの文法 関数 o 利用 name($param 1, $param 2); o 作る function name($param 1){ } <? php // 利用 print date('Y-m-d'); print plus(1, 3); // 作る function plus($first, $secound){ return $first + $secound; } ? >
PHPの文法 配列 <? php $a 1 = array('dog', 'cat', 'bird'); $a 2[0] = 'dog'; $a 2[1] = 'cat'; $a 2[2] = 'bird'; // 表示 print '<pre>'; print_r($a 1); print_r($a 2); print '</pre>'; ? >
PHPの文法 Hash <? php $h 1 = array( 'dog' => '犬', 'cat' => '猫', 'bird' => '鳥' ); $h 2['dog'] = '犬'; $h 2['cat'] = '猫'; $h 2['bird'] = '鳥'; // 表示 print '<pre>'; print_r($h 1); print_r($h 2); print $h 1['dog']; print '</pre>'; ? >
簡単な歴史 o 1995 n o 1998/6 n o PHP 3 2000/5/22 n o PHP/FI PHP 4 2004/7/13 n PHP 5
Classのコード o アクセス制限 n n private o 宣言したクラスだけか らアクセス可能 protected o サブクラスからもアク セス可能 <? php class Test. Class(){ private $attribute 1 = 'dog'; protected $attribute 2 = 'cat'; private function get. Attribute 1(){ return $this->$attribute 1; } function get. Attribute 2(){ return $this->$attribute 2; } } $class = new Test. Class(); print $class->get. Attribute 2(); ? >
例外処理 o try … throw … catch n Javaと同じ <? php class Test. Class(){ private $attribute 1 = 'dog'; protected $attribute 2 = 'cat'; private function get. Attribute 1(){ return $this->$attribute 1; } function get. Attribute 2(){ return $this->$attribute 2; } } $class = new Test. Class(); print $class->get. Attribute 2(); ? >
Classのコード o アクセス制限 n n private o 宣言したクラスだけか らアクセス可能 protected o サブクラスからもアク セス可能 <? php class Test. Class(){ private $attribute 1 = 'dog'; protected $attribute 2 = 'cat'; private function get. Attribute 1(){ return $this->$attribute 1; } function get. Attribute 2(){ return $this->$attribute 2; } } $class = new Test. Class(); print $class->get. Attribute 2(); ? >
Classのコード o アクセス制限 n n private o 宣言したクラスだけか らアクセス可能 protected o サブクラスからもアク セス可能 <? php class File. Not. Found. Exception extends exception { function File. Not. Found. Exception($_error) { $this->error = $_error; } function get. Exception() { return $this->error; } } class My. Class { function open($filename) { if(!file_exists($filename)) throw new File. Not. Found. Exception("file not found"); } } try{ $class = new My. Class(); $class->open("non_exists_file"); } catch(File. Not. Found. Exception $e) { die($e->get. Exception()); } ? >
開発ツール o Eclipse n Tru. Studioプラグイン o n n n o http: //www. xored. com/download. php Apache PHP RDBMS Emacs?
MVC 改変:http: //www. stackasterisk. jp/tech/php/mojavi 01_02. jsp
フレームワーク o mojavi n o Phrame n o http: //www. mojavi. org/ http: //phrame. sourceforge. net/ Wa. Wa n http: //wawawa. jp/
参考文献 o PHP Official Site n o Einführung in PHP und My. SQL n o http: //www. php. net/ http: //www. unigiessen. de/~g 004/php/mysqlserv er 4. gif PHP 5徹底攻略 n http: //www. net-newbie. com/support/
- Slides: 28