Some Code Errors and Advice
I am a student major Software Engineering in SCNU of China.
I have used PHP for nearly one year and I love it for its simpleness.
But it is the book <<Professional PHP6>> make me know more about PHP.
It is really an usefull book!
And here is some code errors I have found in the book(Chinese Version).
1. CH 8 PAGE: 191
//the code in the book
abstract class Event_Handler
{
}
//my code
//according the chart 8-2
abstract class Event_Handler extends Handled
{
}
2. CH 9 PAGE: 201
//the code in the book
$strLogLevel = $this->levelToString($logLevel);
//my code
//it's a static function
$strLogLevel = $Logger::levelToString($logLevel);
And here is some personal advice for the some code.
1. CH7 Page: 181
//the code in the book
private function GetAccessor($strMember){
if($this->blIsLoaded != true){
$this->Load();
}
//the rest code....
}
//my code
private function GetAccessor($strMember){
$this->Load();
//the rest code....
}
//Page 173
public function Load(){
//move the condition here, check whether loaded or not in Load(), to advoid repeat code when call this fun.
if($this->blIsLoade)
return;
if(isset($this->ID)){
//the rest code....
}
}
2. CH 11 PAGE: 251
//the code in the book
$this->arRecipientCollection->addItem($objRecipient, $strIdentifier);
//my code
//should check the value is null or not to ensure it has been initialized, even though it will be created in child's __construct()
if(isset($this->arRecipientCollection))
$this->arRecipientCollection->addItem($objRecipient, $strIdentifier);
3. CH 9 PAGE: 212
//the code in the book
$host = $urlData['host'];
$port = $urlData['port '];
$user = $urlData['user'];
$passwrod= $urlData['passwrod'];
$arPath= explode('/', $urlData['path']);
//my code
//because the urlData should be parsed in the __construct fun
$host = $this->urlData['host'];
$port = $this->urlData['port '];
$user = $this->urlData['user'];
$passwrod= $this->urlData['passwrod'];
$arPath= explode('/', $this->urlData['path']);
PS: I will find others code error at later chapter.
Last edited by chanzonghuang; April 21st, 2012 at 08:55 AM..
|