欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP7匿名類的用法示例

 更新時(shí)間:2019年04月05日 11:24:20   作者:尋歡-  
這篇文章主要介紹了PHP7匿名類的用法,結(jié)合實(shí)例形式分析了php7匿名類、匿名函數(shù)簡單定義與使用技巧,需要的朋友可以參考下

本文實(shí)例講述了PHP7匿名類的用法。分享給大家供大家參考,具體如下:

<?php
/**
 * Created by PhpStorm.
 * User: Itboot
 * Date: 2019/1/17
 * Time: 18:15
 */
class An
{
  private $num;
  protected $age = 15;
  public function __construct() {
    $this->num = 1;
  }
  protected function bar(): int {
    return 10;
  }
  public function drive() {
    return new class($this->num) extends An{
      protected $id;
      public function __construct($num) {
        $this->id = $num;
      }
      public function ea() {
        return $this->id + $this->age + $this->bar();
      }
    };
  }
}
echo (new An())->drive()->ea();

<?php
$fun = function (){
  print '這是匿名函數(shù)'. PHP_EOL;
};
$fun();
class Animal
{
  public $num;
  public function __construct(...$args)
  {
    $this->num = $args[0];
  }
  public function getValue($su): int
  {
    return $this->num + $su;
  }
}
$an = new Animal(4);
echo $an->getValue(12) . PHP_EOL;
echo '匿名類'. PHP_EOL;
echo (new class(11) extends Animal{})->getValue(12);

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《PHP數(shù)組(Array)操作技巧大全》、《PHP基本語法入門教程》、《PHP運(yùn)算與運(yùn)算符用法總結(jié)》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總

希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論