[关闭]
@no13bus 2016-10-22T08:37:07.000000Z 字数 3023 阅读 1425

php7介绍

php7 php


安装

  1. ##查找php包
  2. rpm -qa | grep php
  3. ##删除旧有的php包
  4. rpm -e php包名称

框架性能和升级

5.x到7.0的改变

  1. $first =['a'=>['aa'=>'b']];
  2. $b = 'lala';
  3. echo ${$first['a']['aa']};//结果为 lala
  4. echo $$first['a']['aa'];//php7中无法解析
  1. function a($b,$c)
  2. {
  3. echo $b;
  4. echo $c;
  5. }
  6. call_user_func('a', "111","222");
  7. call_user_func('a', "333","444");
  1. class A {
  2. public function test() { var_dump($this); }
  3. }
  4. // Note: Does NOT extend A
  5. class B {
  6. public function callNonStaticMethodOfA() { A::test(); }
  7. }
  8. (new B)->callNonStaticMethodOfA();
  9. //php7中输出
  10. Deprecated: Non-static method A::test() should not be called statically in /tmp/test.php on line 8
  11. Notice: Undefined variable: this in /tmp/test.php on line 3
  12. NULL
  1. function foo($a, $b, $unused, $unused) {
  2. //
  3. }
  1. function sum(int $a, int $b) {
  2. return $a + $b;
  3. }
  4. var_dump(sum(1, 2));
  5. var_dump(sum(1.5, 2.5)); //会报错
  1. $username = $_GET['user'] ?? 'nobody';
  2. 等于
  3. $username = isset($_GET['user']) ? $_GET['user'] : 'nobody';
  1. echo $a <=> $b;
  1. define('MYARRAY', ['a'=>1,'b'=>2]);
  1. $app->setLogger(new class implements Logger {
  2. public function log(string $msg) {
  3. echo $msg;
  4. }
  5. });

代码示例:

  1. function add(int $left, int $right) {
  2. return $left + $right;
  3. }
  4. try {
  5. echo add('left', 'right');
  6. } catch (Exception $e) {
  7. // Handle exception
  8. } catch (Error $e) { // Clearly a different type of object
  9. // Log error and end gracefully
  10. var_dump($e);
  11. }

错误信息: 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"

总结

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注