Przeglądaj źródła

php链式操作和魔术方法

chenlong 4 lat temu
rodzic
commit
577ab8eb11
3 zmienionych plików z 30 dodań i 1 usunięć
  1. 14 0
      Core/Database.php
  2. 5 1
      index.php
  3. 11 0
      note.txt

+ 14 - 0
Core/Database.php

@@ -0,0 +1,14 @@
+<?php
+namespace Core;
+
+class Database{
+    function where($where){
+        return $this;
+    }
+    function order($order){
+        return $this;
+    }
+    function limit($limit){
+        return $this;
+    }
+}

+ 5 - 1
index.php

@@ -15,4 +15,8 @@ include BASEDIR.'/Core/Loader.php';
  */
 spl_autoload_register('\\Core\\Loader::autoload');
 
-App\Controller\Home\Index::test();
+/**
+ * 面向对象--链式操作
+ */
+//$db = new Core\Database();
+//$db->where()->order()->limit();

+ 11 - 0
note.txt

@@ -0,0 +1,11 @@
+spl常用数据结构
+    堆、栈、队列、数组
+php链式操作
+    return $this;
+魔术方法
+    __get
+    __set
+    __call
+    __callStatic
+    __toString  //将对象当字符串使用
+    __invoke    //将对象当函数使用