Revisiting PHP

巴扎黑
Release: 2016-11-12 15:23:12
Original
1552 people have browsed it
  1. oop mode
    There are two points here
    One is abstract class and interface, they are different. Abstract classes can store methods with function bodies, but interfaces cannot.

abstract class Top
{
   public function getOne();
   public function getTwo();
   public function getThree()
   {
      return 300;
   }
}
class Top_extend extends Top
{
   function getOne()
   {
      return 100;
   }
}
//接口
class interface TopInterface
{
   public function getData();
}
class top_interface implements TopInterface
{
}
//$t = new Top(); //抽象类不能被直接实例化
$t = new Top_extend(); //可以通过实例子类
Copy after login

2. Exception handling

exception.php 异常基类 
//异常基类
class LogException extends Exception
{
var $logfile_dir = 'exception.log';
public function __construct($msg=null,$code=0,$file='')
{
if($file == '')
{
$file = $logfile_dir;
}
$this->saveLog($file);
parent::__construct($msg,$code);
}
//记录日志
protected function saveLog($file)
{
file_put_contents($file,$this->__toString(),FILE_APPEND);
}
}
Copy after login
<?php
//数据库错误类
include_once(&#39;LogException.php&#39;);
class DataBaseException extends LogException
{
protected $databaseErrorMessage;
public function __construct($msg=&#39;&#39;,$code = 0)
{
$this->databaseErrorMessage = $msg;
parent::__construct($msg,$code);
}
public function getMsg()
{
return $this->databaseErrorMessage;
}
}
?>
Copy after login


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!