PHP设计模式笔记二:面向对象 Rango韩老师 http://www.imooc.com/learn/236

SPL标准库的使用

  SPL是用于解决典型问题(standard problems)的一组接口与类的集合。

  1、SPL提供了很多数据结构类,如SplStack、SqlQueue、SqlHeap、SplFixedArray等

  实例代码如下:

    a、栈

    

    b、队列

    

    c、定长数组

    

  2、PHP链式操作的实现

    index.php

    

    IMooc/Database.php

     

  3、PHP魔术方法

    a、__get\__set:对象属性的管理

      index.php

      

      Object.php

      

      output  :  string(19) "IMooc\Object::__get" hello

    b、__call\callStatic:控制对象方法的调用

      index.php

      

      Object.php

      

      output:

        string(4) "test" array(2) { [0]=> string(5) "hello" [1]=> int(123) }
        string(8) "sayHello" array(2) { [0]=> string(8) "helloJiu" [1]=> string(8) "helloPHP" }

    c、__toString():将一个PHP对象转化成字符串

    d、__invoke():将一个对象当成函数调用时,会调用这个函数

      index.php

      

      Object.php

      

      output:

        IMooc\Object
        string(8) "helloJiu"

    

     

原文地址:https://www.cnblogs.com/helloJiu/p/6159110.html