checking for json includes... /usr/local/Cellar/php@7.2/7.2.29/include/php checking for redis json support... enabled checking for igbinary includes... configure: error: Cannot find igbinary.h ERROR: `/private/tmp/pear/temp/redis/configure --with-php-config=/usr/local/opt/php@7.2/bin/php-config --enable-redis-igbinary=y --enable-redis-lzf=y --enable-redis-zstd=y' failed
1
$ pecl install igbinary
可能又会出现
1 2 3 4
... checking for libzstd files in default path... not found configure: error: Please reinstall the libzstd distribution ERROR: `/private/tmp/pear/temp/redis/configure --with-php-config=/usr/local/opt/php@7.2/bin/php-config --enable-redis-igbinary=y --enable-redis-lzf=y --enable-redis-zstd=y' failed
安装 swoole
1
$ pecl install swoole
在安装 swoole 的时候会遇到
错误信息如下:
1 2 3 4 5 6 7 8
.... In file included from /private/tmp/pear/temp/swoole/php_swoole.h:53: /private/tmp/pear/temp/swoole/include/swoole.h:620:10: fatal error: 'openssl/ssl.h' file not found #include <openssl/ssl.h> ^~~~~~~~~~~~~~~ 1 error generated. make: *** [php_swoole_cxx.lo] Error 1 ERROR: `make' failed
为了更简洁, 这个意味着我们可以这样简写并不意味着我们就应该这么写. 但是, 当我们写简洁代码的时候, 这种方式会看起来更清楚, 我们应该这么写, (并且这个特性允许我们在多种情况下使用这个运算符[this feature allows us to DRY up the ternary operator in many cases])
# 生产依赖 Would you like to define your dependencies (require) interactively [yes]?
require-dev
开发依赖, 这里我们加入 phpunit 作为单元测试依赖
1 2 3 4 5 6 7 8 9 10 11 12 13 14
Would you like to define your dev dependencies (require-dev) interactively [yes]?
Search for a package: phpunit
Found 15 packages matching phpunit
[0] phpunit/phpunit ... [14] brianium/paratest
Enter package # to add, or the complete package name if it is not listed: 0 Enter the version constraint to require (or leave blank to use the latest version): Using version ^8.5 for phpunit/phpunit Search for a package:
Would you like to install dependencies now [yes]? yes Loading composer repositories with package information Updating dependencies (including require-dev) Package operations: 29 installs, 0 updates, 0 removals - Installing sebastian/version (2.0.1): Downloading (100%) ...... - Installing phpunit/phpunit (8.5.8): Downloading (100%) sebastian/global-state suggests installing ext-uopz (*) phpunit/phpunit suggests installing phpunit/php-invoker (^2.0.0) Package phpunit/php-token-stream is abandoned, you should avoid using it. No replacement was suggested. Writing lock file Generating autoload files 5 packages you are using are looking for funding. Use the `composer fund` command to find out more!
明白他的意思吗? && 为 同时真 运算符. A && B, 只有当 A 和 B 都为真的时候,这句才是真 PHP 会先判断A是否为真, 若A为真的话 就会继续判断B. 所以,当 A 为真, B 是一个语句的时候, B 就会运行. 同理,当 A 为假的时候, 这句一定是假, 就没有必要往后判断了, 此时, B 就不会运行. ||, or 则不同 A or B, 只要 A 或者 B 中有一个是真, 这句就是真 PHP先判断 A 是否为真, 若 A 为真的话, 此句一定是真, 没有必要再去判断B 所以当 A 为假的时候, PHP会继续判断 B 是不是真, 才能得到这句的结果 此是, B如果是一个语句就会运行. 还记得入门时候那数据连接那句吗? 现在应该很好懂为什么加个OR了吧?
1
mysql_connect($host,$user,$pwd) or die('Mysql Error!');
Analyzes if PHP4 functions (intval, floatval, doubleval, strval) are used for type casting and generates hints to use PHP5’s type casting construction (i.e. ‘(type) parameter’).
1 2 3 4 5
// bad $input = strval($_POST['name']);
// good $input = (string) $_POST['name'];
4. 合并 isset 的多重判定
The inspection is advising when multiple ‘isset(…)’ statements can be merged into one
1 2 3 4 5 6 7 8 9
// bad if (isset($dir['origin']) && isset($dir['doc'])) { // ... }
// good if (isset($dir['origin'], $dir['doc'])) { // ... }
5. If 多条件语法的合并
1 2 3 4 5 6 7 8 9 10 11
// bad if ($profile->chid_status === UserProfile::STATUS_FAIL) { if ($profile->chid_failed_at) { // ... } }
// good if ($profile->chid_status === UserProfile::STATUS_FAIL && $profile->chid_failed_at) { // ... }