@no13bus
2016-10-22T08:37:07.000000Z
字数 3023
阅读 1504
php7
php
##查找php包
rpm -qa | grep php
##删除旧有的php包
rpm -e php包名称
/etc/php-fpm.d/www.conf
这个php-fpm的启动配置里面, 编辑里面的user和group为www 不然会报403错误。fastcgi_pass 127.0.0.1:9001;
和/etc/php-fpm.d/www.conf
中的监听地址listen = 127.0.0.1:9001
需要一致sudo /etc/rc.d/init.d/php-fpm restart
重启php-fpm解析器
$first =['a'=>['aa'=>'b']];
$b = 'lala';
echo ${$first['a']['aa']};//结果为 lala
echo $$first['a']['aa'];//php7中无法解析
function a($b,$c)
{
echo $b;
echo $c;
}
call_user_func('a', "111","222");
call_user_func('a', "333","444");
<script language="php"></php>
这样的标签php7已经不支持了
class A {
public function test() { var_dump($this); }
}
// Note: Does NOT extend A
class B {
public function callNonStaticMethodOfA() { A::test(); }
}
(new B)->callNonStaticMethodOfA();
//php7中输出
Deprecated: Non-static method A::test() should not be called statically in /tmp/test.php on line 8
Notice: Undefined variable: this in /tmp/test.php on line 3
NULL
function foo($a, $b, $unused, $unused) {
//
}
declare(strict_type=1);
或者php.ini里面开启。作用于函数调用和返回。strict_types指令只影响指定使用的文件,不会影响被它包含(通过include等方式)进来的其他文件(为了向下兼容)。
function sum(int $a, int $b) {
return $a + $b;
}
var_dump(sum(1, 2));
var_dump(sum(1.5, 2.5)); //会报错
$username = $_GET['user'] ?? 'nobody';
等于
$username = isset($_GET['user']) ? $_GET['user'] : 'nobody';
echo $a <=> $b;
define('MYARRAY', ['a'=>1,'b'=>2]);
$app->setLogger(new class implements Logger {
public function log(string $msg) {
echo $msg;
}
});
代码示例:
function add(int $left, int $right) {
return $left + $right;
}
try {
echo add('left', 'right');
} catch (Exception $e) {
// Handle exception
} catch (Error $e) { // Clearly a different type of object
// Log error and end gracefully
var_dump($e);
}
错误信息: string(123) "Argument 1 passed to add() must be of the type integer, string given, called in /alidata/www/huxintong/index.php on line 60"