close

最近再學習phpunit,發現ModerPHP這本書上所說的,需要使用bootstrap的檔案去require autoload的檔案,似乎在PHPUnit 8.0.2之後就不需要使用了。因為我的phpunit是透過composer一起下載的,故phpunit好像也會自動載入composer的autoload了!!。

2019-02-10


最近一直犯傻把 $_SERVER['DOCUMENT_ROOT']; 當作 dirname(__DIR__); 再用。

$_SERVER['DOCUMENT_ROOT'] 其實就是你SERVER架起來後的位置,

舉例:我們常常在開發測試環境時,使用php -S localhost:4000  架設私人Server進行測試,

 則會根據你在哪個資料夾輸入這個指令,把該路徑當成$_SERVER['DOCUMENT_ROOT'];

檔案路徑範例     E:\JobR\forJob\PdoManager\test

Code:

Output: 

當要require autoload.php,個人覺得使用dirname(__DIR__),從當前檔案位置去尋找相對應的位置較不容易產生錯誤。

Example 2:

如果直接使用php去跑檔案,可以發現因為沒有架設Server所以找不到Document_Root。


On Windows, both slash (/) and backslash (\) are used as directory separator character. In other environments, it is the forward slash (/).

from PHP manual

我一直以為Windows filesystem是使用  \  所以只能使用  \  沒想到其實windows也可以接受 /  ,難怪我在command line的時候都可以通!

我想這就是為什麼php 可以統一使用  /  ,這樣既兼容windows 也兼容 linux,唯一的缺點就是在做preg_match,會因為windows取出來的是 

 \  而導致,取代上的問題,這時候就可以使用之前討論的 DIRECTORY_SEPARATOR來解決,又或者是str_replace('\\','/',$str),將其轉為統一格式!!!


放棄Mysql語法改使用PDO或mysqli的方式,以避免SQLInjection

參考連結:  https://web.archive.org/web/20171107192133/https://blog.csdn.net/hornedreaper1988/article/details/43520257 


Don't use UTF-8 in Mysql 

Use utf8_mb4 instead.

參考連結:

http://mitblog.pixnet.net/blog/post/43827108-%5Bmysql%5D-%E7%82%BA%E4%BB%80%E9%BA%BC-mysql-%E8%A6%81%E8%A8%AD%E5%AE%9A%E7%94%A8-utf8mb4-%E7%B7%A8%E7%A2%BC-utf8mb4_  香腸炒魷魚 大大 詳細解說

 https://www.infoq.cn/article/in-mysql-never-use-utf8-use-utf8

arrow
arrow

    蕭瑞文 發表在 痞客邦 留言(0) 人氣()