Archive for the ‘PHP’ Category

解决php 5.3 deprecated 错误问题

Friday, November 13th, 2009

最近邮件中收到很多业界PHP朋友关于php 5.3 在安装过程中遇到原有程序错误问题,较常见是php 5.3 deprecated错误。那么我今天就一起对类似问题给大家做一个回复性的总结吧。也顺便让今后有遇到同类问题的人一个解决问题的参考思路。

   php 5.3 从一方面来讲,可以说在07年计划PHP6的中的一个pre版本,增加了很多功能,统一了很多语法,使PHP变得更加强大与简洁。

    说到统计架构规划,PHP当然会对一些别名,重复功能function进行归类整理,并把一些不用的正式在php 5.3以后删除掉.故不建议在新项目继续使用.

PHP 5.3 有两个deprecated,

E_DEPRECATED and E_USER_DEPRECATED

以下是在旧的项目中会在php 5.3以后碰到的问题

Deprecated functions:

Deprecated features:

  • 直接返加new 实例不再建议使用. PHP 6 将不再支持
  • Call-time pass-by-reference 参数现在不再建议使用 PHP 6 将不再支持
  • 用 {} 访问字符串顺序不再建议使用. 统一用 [] 代替. PHP 6 将不再支持

 

当然如果项目紧急,又要在php 5.3 使用以上方法,可以用下面的方法去做

在php.ini 增加

cd /home/jiania/lnamp/php530/etc/php.ini

php_flag allow_call_time_pass_reference On
php_value error_reporting “E_ALL & ~E_NOTICE & ~E_DEPRECATED”

PHP设计模式之观察者模式实现DEMO

Sunday, March 2nd, 2008

<?php
/**
 * Jiania之观察者模式实现DEMO
 *
 * @package SPL
 * @subpackage SPL_SpLObserver
 * @author Jiania J Hung<jiania@gmail.com>
 * @since PHP5.1.x
 * @copyright http://www.jiania.com
 *
 */
class boy implements SplObserver
{
 private $name;
 
 public function __construct($name)
 
 {
  $this->name=$name;
 }
 
 public function update(SplSubject $subject)
 {
  echo  $this->name.” Says:I love you.\n”;
 }
}

class girl implements SplObserver
{
 private $name;
 
 public function __construct($name)
 {
  $this->name=$name;
 }
 public function update(SplSubject $subject)
 {
  echo  $this->name.”Says:I love you.\n”;
 }
}

class sweetie implements SplSubject
{
 private $name;
 private $people;
 private $state;
 
 public function __construct($name)
 {
  $this->people=new SplObjectStorage();
  $this->name=$name;
 }
 
 public function attach(SplObserver $observer)
 {
  $this->people->attach($observer);
 }
 
 public function detach(SplObserver $observer)
 {
  $this->people->detach($observer);
 }
 
 public function notify()
 {
  foreach ($this->people as $person)
  {
   $person->update($this);
  }
 }
 
 function count()
 {
  return $this->people->count();
 }
 function contains($obj)
 {
  return $this->people->contains($obj);
 }

 public function getState()
 {
  return $this->state;
 }
 public function setState($state)
 {
  return $this->state=$state;
 }
 public function getName()
 {
  return $this->name.”\n”;
 }
}
$sweetie=new sweetie(‘Jiania family’);
$boy=new boy(‘jiania’);
$girl=new girl(‘dreamer’);
$sweetie->attach($boy);
$sweetie->attach($girl);
echo $sweetie->getState();
$sweetie->notify();

for与foeach,while等深入比较与研究

Sunday, February 3rd, 2008

本文摘自<PHP编程思想>一书,版权属于洪建家所有,请尊重版权.

PHP编程思想之for,foreach,while,do-while深入讲解
初学编

1.1 for循环语句

for语句的格式为:

概念:for是计次数循环,其执行次数由循环变量的终值减去初值再除以步长得出.

for (初始化语句; 条件语句; 控制语句)
{
语句1 ;
语句2 ;
….

语句n ;
}
for 语句的执行顺序如下:
首先执行“初始化语句”,无条件被执行一次,然后测试“条件语句”
若条件成立,则执行语句1到语句n;然后执行“控制”语句.程序完成第一过程体.
接下来程序会再测试条件语句是否成立,如果成立则重复执行以上过程,直至条件不成立时才结束for循环.

DEMO:

demo 1写法

<?php

for($i=0;$i<10;$i++)
{
echo $i.”\r\n”;
}
?>

demo 2 写法

<?php
for($i=0;$i<10;$i++):
echo $i.”\r\n”;
endfor;
?>

demo 3 写法

<?php
$i=0;
for(;;)//注意初始化语句与条件语句与控件语句都为空
{
if($i>10){
break;
}
echo $i.”\r\n”;
$i++;
}
?>
1.2 foreach 循环

foreach (数组 as 数组值)
{
语句1 ;
语句2 ;
….

语句n ;

}
foreach (数组 as 数组键名 => 数组值)

{
语句1 ;
语句2 ;
….

语句n ;

}

注:
1.第二种写法主要是扩展第一种写法;
2.执行时,数组内部的指针会自动指向第一个单元,这意味着在做数组循环时不需要调用 reset()方法.程序结束后,指针返回数组尾端.
3.foreach 所操作的是指定数组的一个拷贝,而不是该数组本身,如果想改变数组,可以在执行之前用引用方法改变.
4.foreach 不支持用“@”来抑制错误信息的能力。
5.foreach 可以遍历对象

1.3 while 循环

while循环和for循环类似,其格式为:

while (条件语句)
{
语句1 ;
语句2 ;
….

语句n ;
}

解说:

执行while时,先测试“条件语句”,如果条件成立,则执行语句1到语句n,直至条件不成立时结束循环。

故如果当条件为false时,那么循环体一次都不会被执行.当循环体执行由True转变到False语句时,才会结束循环

DEMO:

demo 1写法
<?php
while ($i<10)
{
 $i++;
 echo $i”\r\n”;
}
?>

demo 2写法

<?php
while ($i<10):
{
 $i++;
 echo $i.”\r\n”;
}
endwhile;
?>

1.4 do-while循环
do
{
语句1 ;
语句2 ;
….

语句n ;
while(条件语句)
}

do-while与while 循环最大区别在于表达式的值是在每次循环结束时检查而不是开始时,所以 do-while 的循环体保证会执行一次.

demo

<?php
$i=9;
do {
    if ($i < 10) {
        echo $i.”\r\n”;
        break;
    }
} while(0);

未完,待继
?>

之PDO数据层深入讲解

Tuesday, January 29th, 2008

在PHP5,6系列中,主要有四个类,因为开发领导者与SPL是同一个人,所以关联相关厉害,它们分别是
class PDOException extends RuntimeException
class PDO

class PDOStatement implements Traversable

final class PDORow

Classes [4] {
Class [ <internal:PDO> class PDOException extends RuntimeException ] {

- Constants [0] {
}

- Static properties [0] {
}

- Static methods [0] {
}

- Properties [5] {
Property [ <default> protected $message ]
Property [ <default> protected $code ]
Property [ <default> protected $file ]
Property [ <default> protected $line ]
Property [ <default> public $errorInfo ]
}

- Methods [9] {
Method [ <internal, inherits Exception> final private method __clone ] {
}

Method [ <internal, inherits Exception, ctor> public method __construct ] {

- Parameters [2] {
Parameter #0 [ <optional> $message ]
Parameter #1 [ <optional> $code ]
}
}

Method [ <internal, inherits Exception> final public method getMessage ] {
}

Method [ <internal, inherits Exception> final public method getCode ] {
}

Method [ <internal, inherits Exception> final public method getFile ] {
}

Method [ <internal, inherits Exception> final public method getLine ] {
}

Method [ <internal, inherits Exception> final public method getTrace ] {
}

Method [ <internal, inherits Exception> final public method getTraceAsString ] {
}

Method [ <internal, inherits Exception> public method __toString ] {
}
}
}

Class [ <internal:PDO> class PDO ] {

- Constants [77] {
Constant [ integer PARAM_BOOL ] { 5 }
Constant [ integer PARAM_NULL ] { 0 }
Constant [ integer PARAM_INT ] { 1 }
Constant [ integer PARAM_STR ] { 2 }
Constant [ integer PARAM_LOB ] { 3 }
Constant [ integer PARAM_STMT ] { 4 }
Constant [ integer PARAM_INPUT_OUTPUT ] { -2147483648 }
Constant [ integer PARAM_EVT_ALLOC ] { 0 }
Constant [ integer PARAM_EVT_FREE ] { 1 }
Constant [ integer PARAM_EVT_EXEC_PRE ] { 2 }
Constant [ integer PARAM_EVT_EXEC_POST ] { 3 }
Constant [ integer PARAM_EVT_FETCH_PRE ] { 4 }
Constant [ integer PARAM_EVT_FETCH_POST ] { 5 }
Constant [ integer PARAM_EVT_NORMALIZE ] { 6 }
Constant [ integer FETCH_LAZY ] { 1 }
Constant [ integer FETCH_ASSOC ] { 2 }
Constant [ integer FETCH_NUM ] { 3 }
Constant [ integer FETCH_BOTH ] { 4 }
Constant [ integer FETCH_OBJ ] { 5 }
Constant [ integer FETCH_BOUND ] { 6 }
Constant [ integer FETCH_COLUMN ] { 7 }
Constant [ integer FETCH_CLASS ] { 8 }
Constant [ integer FETCH_INTO ] { 9 }
Constant [ integer FETCH_FUNC ] { 10 }
Constant [ integer FETCH_GROUP ] { 65536 }
Constant [ integer FETCH_UNIQUE ] { 196608 }
Constant [ integer FETCH_KEY_PAIR ] { 12 }
Constant [ integer FETCH_CLASSTYPE ] { 262144 }
Constant [ integer FETCH_SERIALIZE ] { 524288 }
Constant [ integer FETCH_PROPS_LATE ] { 1048576 }
Constant [ integer FETCH_NAMED ] { 11 }
Constant [ integer ATTR_AUTOCOMMIT ] { 0 }
Constant [ integer ATTR_PREFETCH ] { 1 }
Constant [ integer ATTR_TIMEOUT ] { 2 }
Constant [ integer ATTR_ERRMODE ] { 3 }
Constant [ integer ATTR_SERVER_VERSION ] { 4 }
Constant [ integer ATTR_CLIENT_VERSION ] { 5 }
Constant [ integer ATTR_SERVER_INFO ] { 6 }
Constant [ integer ATTR_CONNECTION_STATUS ] { 7 }
Constant [ integer ATTR_CASE ] { 8 }
Constant [ integer ATTR_CURSOR_NAME ] { 9 }
Constant [ integer ATTR_CURSOR ] { 10 }
Constant [ integer ATTR_ORACLE_NULLS ] { 11 }
Constant [ integer ATTR_PERSISTENT ] { 12 }
Constant [ integer ATTR_STATEMENT_CLASS ] { 13 }
Constant [ integer ATTR_FETCH_TABLE_NAMES ] { 14 }
Constant [ integer ATTR_FETCH_CATALOG_NAMES ] { 15 }
Constant [ integer ATTR_DRIVER_NAME ] { 16 }
Constant [ integer ATTR_STRINGIFY_FETCHES ] { 17 }
Constant [ integer ATTR_MAX_COLUMN_LEN ] { 18 }
Constant [ integer ATTR_EMULATE_PREPARES ] { 20 }
Constant [ integer ATTR_DEFAULT_FETCH_MODE ] { 19 }
Constant [ integer ERRMODE_SILENT ] { 0 }
Constant [ integer ERRMODE_WARNING ] { 1 }
Constant [ integer ERRMODE_EXCEPTION ] { 2 }
Constant [ integer CASE_NATURAL ] { 0 }
Constant [ integer CASE_LOWER ] { 2 }
Constant [ integer CASE_UPPER ] { 1 }
Constant [ integer NULL_NATURAL ] { 0 }
Constant [ integer NULL_EMPTY_STRING ] { 1 }
Constant [ integer NULL_TO_STRING ] { 2 }
Constant [ string ERR_NONE ] { 00000 }
Constant [ integer FETCH_ORI_NEXT ] { 0 }
Constant [ integer FETCH_ORI_PRIOR ] { 1 }
Constant [ integer FETCH_ORI_FIRST ] { 2 }
Constant [ integer FETCH_ORI_LAST ] { 3 }
Constant [ integer FETCH_ORI_ABS ] { 4 }
Constant [ integer FETCH_ORI_REL ] { 5 }
Constant [ integer CURSOR_FWDONLY ] { 0 }
Constant [ integer CURSOR_SCROLL ] { 1 }
Constant [ integer MYSQL_ATTR_USE_BUFFERED_QUERY ] { 1000 }
Constant [ integer MYSQL_ATTR_LOCAL_INFILE ] { 1001 }
Constant [ integer MYSQL_ATTR_INIT_COMMAND ] { 1002 }
Constant [ integer MYSQL_ATTR_READ_DEFAULT_FILE ] { 1003 }
Constant [ integer MYSQL_ATTR_READ_DEFAULT_GROUP ] { 1004 }
Constant [ integer MYSQL_ATTR_MAX_BUFFER_SIZE ] { 1005 }
Constant [ integer MYSQL_ATTR_DIRECT_QUERY ] { 1006 }
}

- Static properties [0] {
}

- Static methods [1] {
Method [ <internal:PDO> static public method getAvailableDrivers ] {
}
}

- Properties [0] {
}

- Methods [15] {
Method [ <internal:PDO, ctor> public method __construct ] {

- Parameters [4] {
Parameter #0 [ <required> $dsn ]
Parameter #1 [ <required> $username ]
Parameter #2 [ <required> $passwd ]
Parameter #3 [ <optional> $options ]
}
}

Method [ <internal:PDO> public method prepare ] {

- Parameters [2] {
Parameter #0 [ <required> $statment ]
Parameter #1 [ <optional> $options ]
}
}

Method [ <internal:PDO> public method beginTransaction ] {
}

Method [ <internal:PDO> public method commit ] {
}

Method [ <internal:PDO> public method rollBack ] {
}

Method [ <internal:PDO> public method setAttribute ] {

- Parameters [2] {
Parameter #0 [ <required> $attribute ]
Parameter #1 [ <required> $value ]
}
}

Method [ <internal:PDO> public method exec ] {

- Parameters [1] {
Parameter #0 [ <required> $query ]
}
}

Method [ <internal:PDO> public method query ] {
}

Method [ <internal:PDO> public method lastInsertId ] {

- Parameters [1] {
Parameter #0 [ <optional> $seqname ]
}
}

Method [ <internal:PDO> public method errorCode ] {
}

Method [ <internal:PDO> public method errorInfo ] {
}

Method [ <internal:PDO> public method getAttribute ] {

- Parameters [1] {
Parameter #0 [ <required> $attribute ]
}
}

Method [ <internal:PDO> public method quote ] {

- Parameters [2] {
Parameter #0 [ <required> $string ]
Parameter #1 [ <optional> $paramtype ]
}
}

Method [ <internal:PDO> final public method __wakeup ] {
}

Method [ <internal:PDO> final public method __sleep ] {
}
}
}

Class [ <internal:PDO> <iterateable> class PDOStatement implements Traversable ] {

- Constants [0] {
}

- Static properties [0] {
}

- Static methods [0] {
}

- Properties [1] {
Property [ <default> public $queryString ]
}

- Methods [21] {
Method [ <internal:PDO> public method execute ] {

- Parameters [1] {
Parameter #0 [ <optional> $bound_input_params ]
}
}

Method [ <internal:PDO> public method fetch ] {

- Parameters [3] {
Parameter #0 [ <optional> $how ]
Parameter #1 [ <optional> $orientation ]
Parameter #2 [ <optional> $offset ]
}
}

Method [ <internal:PDO> public method bindParam ] {

- Parameters [5] {
Parameter #0 [ <required> $paramno ]
Parameter #1 [ <required> &$param ]
Parameter #2 [ <optional> $type ]
Parameter #3 [ <optional> $maxlen ]
Parameter #4 [ <optional> $driverdata ]
}
}

Method [ <internal:PDO> public method bindColumn ] {

- Parameters [5] {
Parameter #0 [ <required> $column ]
Parameter #1 [ <required> &$param ]
Parameter #2 [ <optional> $type ]
Parameter #3 [ <optional> $maxlen ]
Parameter #4 [ <optional> $driverdata ]
}
}

Method [ <internal:PDO> public method bindValue ] {

- Parameters [3] {
Parameter #0 [ <required> $paramno ]
Parameter #1 [ <required> $param ]
Parameter #2 [ <optional> $type ]
}
}

Method [ <internal:PDO> public method rowCount ] {
}

Method [ <internal:PDO> public method fetchColumn ] {

- Parameters [1] {
Parameter #0 [ <optional> $column_number ]
}
}

Method [ <internal:PDO> public method fetchAll ] {

- Parameters [3] {
Parameter #0 [ <optional> $how ]
Parameter #1 [ <optional> $class_name ]
Parameter #2 [ <optional> $ctor_args ]
}
}

Method [ <internal:PDO> public method fetchObject ] {

- Parameters [2] {
Parameter #0 [ <required> $class_name ]
Parameter #1 [ <optional> $ctor_args ]
}
}

Method [ <internal:PDO> public method errorCode ] {
}

Method [ <internal:PDO> public method errorInfo ] {
}

Method [ <internal:PDO> public method setAttribute ] {

- Parameters [2] {
Parameter #0 [ <required> $attribute ]
Parameter #1 [ <required> $value ]
}
}

Method [ <internal:PDO> public method getAttribute ] {

- Parameters [1] {
Parameter #0 [ <required> $attribute ]
}
}

Method [ <internal:PDO> public method columnCount ] {
}

Method [ <internal:PDO> public method getColumnMeta ] {

- Parameters [1] {
Parameter #0 [ <required> $column ]
}
}

Method [ <internal:PDO> public method setFetchMode ] {

- Parameters [2] {
Parameter #0 [ <required> $mode ]
Parameter #1 [ <optional> $params ]
}
}

Method [ <internal:PDO> public method nextRowset ] {
}

Method [ <internal:PDO> public method closeCursor ] {
}

Method [ <internal:PDO> public method debugDumpParams ] {
}

Method [ <internal:PDO> final public method __wakeup ] {
}

Method [ <internal:PDO> final public method __sleep ] {
}
}
}

Class [ <internal:PDO> final class PDORow ] {

- Constants [0] {
}

- Static properties [0] {
}

- Static methods [0] {
}

- Properties [0] {
}

- Methods [0] {
}
}
}
}

PHP编程思想|->SPL|模块化|Zend引擎核心

Tuesday, January 22nd, 2008

所有的SPL->Zend引擎核心都是基于C底层实现

ArrayAccess 接口

注:重载任何对象数组访问功能接口

Exception    错误基类

注意:PHP5,6以后最核心的错误处理基类,分逻辑错误与实时错误等众多子孙类,SPL王国大将,地位相当于现在中国公检法部门角色

Iterator      迭代器接口

注:SPL国王Traversable儿子,跟它母亲foreach在处理自己的王业时配合相当好.

IteratorAggregate 外部迭代器接口

注:SPL国王Traversable儿子,历史的不幸,只是做Iterator政治上的配角.不过他对名将ArrayObject影响是深远的.

Serializable 串行序列化接口

注:允许类自定串行序列等功能,此角色较小心眼,任何类实现它后不能再使用__sleep() 与 __wakeup()方法

Traversable 通用型接口,SPL国王

PHP编程思想|->SPL篇-Traversable接口

Tuesday, January 22nd, 2008

读者对象:所有级别PHPER 

今天建家给大伙讲讲SPL最底层的Traversable接口,为了照顾大多数PHPER英语阅读理解的不足,我先与大家一起学习Traversable的中文意思,Traversable的意思就是:可通行,能越过的.在SPL我的解释是SPL通行接口,它基本上可以说是SPL的老祖宗.是它带邻大家创立了SPL王国,底下有两个出息的儿子,个个创出不凡的家业.他们是 IteratorAggregate 与Iterator 

特点:集进ZendEngine
摘要: 此接口可以实现类中foreach功能

可从:PHP 5.0 起可以使用这个接口

 这老宗祖有点个性,它不能单独被实现(implematation).一个人无法创立王国,王位必需继承下去,也就是说必需与他儿子
 IteratorAggregate 或是Iterator 其中的一个一起实现接口,才能把让王国继续下去.^_^
 前面提到有点例外,就是对Traversable国王的皇后foreach 例外.提到Traversable的夫人foreach,在人类的PHP世界或是SPL皇宫世界里头,贡献实在不可低估.以至Traversable国王说,如果没有美丽的foreach一直帮朕协调解决王国所有关系圈.朕根本不可能把SPL皇城管理这样好.

interface Traversable
{
}

什么时候不用foreach()

Sunday, January 20th, 2008

什么时候不用foreach()
在编辑业界中,我发现大多数人这样写代码
<?php
  foreach($array as $key=>$value) {
    $array[$key] = some_function($value);
  }
?>
但上面的方面在Zend引擎2的环境中运行相当慢

下面介绍两绍正确的写法

<?php

foreach($array as $key=>&value)
{
$valve=some_function($v);
}
?>
或是这样

<?php
  array_map(‘some_function’,$array);
?>
这样使用
//someObject 是array_map回调函数
<?php
  array_map(array(‘someObject’,'someMethod’),$arr);
?>

jiania->PHP扫盲版大全之变量名与赋值

Thursday, January 10th, 2008

jiania->PHP扫盲版大全2

<?php
/**
* package StudyPHP_Base
* Class  1.php
* author:jiania
* copyright www.jiania.com
* email jiania@gmail
* msn jiania@gmail.com
* skype:jiania
* mobile:13520000517
*/

/**
* 变量命名与赋值,简单加演示!
*/

$a=1;
$b=2;
$c=3;
$d=$a+$b+$c;
$e=$a*$b*$c;
$f=$a/$b/$c;
$g=$a-$b-$c;
echo $d;
echo “<br>”;
echo $e;
echo “<br>”;
echo $f;
echo “<br>”;
echo $g;
echo “<br>”;
echo $a|$b&$c;
?>

jiania->商业应用之防机器程序PHP终结者

Thursday, January 10th, 2008

我们在各类商业应用中,往往会推出各种商业活动,如投票中奖,注册发贴,查看.可是总有一些别有用心的人会这样,写个机器程序,把你几天的成果付出东流.现在jiania就给出一个可行方案

手法一般是这样

1.搜索几十,上百个代理IP,模似访问,注册,投票;

2.写个采集程序,较高级者用CURL,更高级者用shell account SSL做代理.

3….等很多

解决方法如下:

1.常用方法就是限制单个IP一定时间访问量.但破解很简单,弄几个IP就可以

2.取得HTTP_REFERFER的信息做分析,破解更简单,直接改变客户端HTTP_REFERER信息

3.提取客户端的机器名,以客户端机器名做为分析点,这方法目前较有效.很少程序有用到.祝大家好运.

<?php
$ip=$_SERVER['REMOTE_ADDR'];
echo gethostbyaddr($ip);
echo “<BR>”;
?>

上面的代码可能对小区宽带失灵,最好方法用JS取得客户机器名,再用ajax传给php

回复一位PHPER的面试题解答

Thursday, January 10th, 2008

.什么是引用?引用的优缺点,还有关于函数返回引用的问题.

2.有一道php的题是让我完成一个类的接口,我不明白什么是接口,希望高手指点.

3.遇到了一些关于类的问题, public static的用途什么的,希望大家给个相关教程看看.

4.下面着段代码
<?php
// 注意在 4.0.0-RC2 之前不存在 !== 运算符

if ($handle = opendir(‘/path/to/files’)) {
    echo “Directory handle: $handle\n”;
    echo “Files:\n”;

    /* 这是正确地遍历目录方法 */
    while (false !== ($file = readdir($handle))) {
        echo “$file\n”;
    }

    closedir($handle);
}
?>

为什么false !==这里用!==而不用!=  ?

5.今天让我完成的那个类文件最后没有?>,   这样有什么意义么?
我的回复如下:

做为资深面试官解答如下:
1.通常在大型程序中,对引用的深入理解与处理影响到相关代码的执行效率问题,不正确处理引用会使程序效率低35%以上,如关联程序过多,会更慢.那么什么是引用呢?要明白引用首先你得先明白什么是变量?$name=”jiania”,这里的$name就是变量,如果$username=&$name,那么我们就说变量$username与变量$name指向同一个对象,就是jiania,也就是说他们指向同一个地方.在function或是OO中,又有点需要注意的
举例:
环境:php5.1.6起
$powman=new jiania();
注意new jiania()前面并没有&,如果加了会出现错误,因为在高版本中,这里的引用交给Zend 引擎来处理,它对这个进行了限制.

b.如果在一个函数内部给一个声明为 global 的变量赋于一个引用,该引用只在函数内部可见。可以通过使用 $GLOBALS 数组避免这一点。
c.复杂数组最好拷贝而不是引用。
d.$this ,在一个对象的方法中,$this 永远是调用它的对象的引用。
2.其实楼主面试不知是什么层次的程序员,php有关接口在现实中很少程序员真正使用到。当然现在玩框架的人例外.我本身是一名JAVA程序员,从05开发PHP框架起,在接口上有一些理解。现讲解一下。
如果你要明白接口,首先你得明白什么叫对象,那什么是对象呢?万物皆对象,把所有的东西当成对象,比如我的名字叫洪建家,我孩子的名字叫小家家,这里的名字就是对象,洪建家与小家家都是人,这就是类,OK,明白了什么是类与对象,接下来我跟你讲讲什么是抽像类,现实中我们常会描述一些对象,但却没有具体的实现方法,这样的类就是抽象类,比如
abstract class CallMe{
        abstract function showMe();
               
}
class Callson extends CallMe {
    function showMe{
        print “Callson::showMe()\n”;
    }
}
这里的CallMe就是抽像类,抽像类只能通过子类来具体实现。OK,明白了什么叫抽像类,我们下面再来讲解什么是接口。
对于初学者,你可以理解接口(interface)是抽象类的变体。可能会有一些刚接触OO的人会问,那为何还需要区别什么是接口,什么是抽像类,答接口是用于实现多重继承。以下是一个接口的简单演示,注意实现任何接口必需用implements关键字

<?php

interface JianiaHome {
        function boss();
}
       
class xiojiajia implements JianiaHome{
        public function boss()
        {
                echo “hongjianjia”;
        }
}

?>
其它问题在我的PHP扫盲手册里…自己网上找我发的信息吧。