我所認識的php(下集)
這一篇大概會變得比較像雜記了.. 主要是來寫我所看到的一些程式的寫法。 其他順便介紹一些php好用的函式庫。 在A的建構子裡面直接將物件B建立起來放入某個變數中。 嗯...雖然知道能這樣用, 但目前還不知道這樣的好處何在。 <?php class A { var $B ; function __construct ( ) { $this -> B = new B ( ) ; } //do some other things } class B { var $children_of_class_b = 'somevalue' ; //something in class B } $A = new A ; echo $A -> B -> children_of_class_b ; ?> 寫完之後突然想到, 要怎麼將資料存成物件呢? 於是看到有以下兩種方法。 第一種是直接宣告一個物件然後下面慢慢定義。 第二種則是從陣列然後直接變形成物件。 $book = new stdClass ; $book -> title = "Harry Potter and the Prisoner of Azkaban" ; $book -> author = "J. K. Rowling" ; $book -> publisher = "Arthur A. Levine Books" ; $book -> amazon_link = "http://www.amazon.com/dp/0439136369/" ; $array = array ( "title" => "Harry Potter and the Prisoner of Azkaban" , "autho...