PHP中=>、->、::的用法记录

☆=>

$css = array('style' => '0', 'color' => 'green');
$css['style']==='0',$css['color']=='green';

☆->

$arr=['a'=>123,'b'=>456];//数组初始化
echo $arr['a'];//数组引用
print_r($arr);//查看数组
class A{
  public $a=123;
  public $b=456;
}
$obj=new A();
echo $obj->a;//对象引用
print_r($obj);//查看对象

☆::
双冒号操作符即作用域限定操作符Scope Resolution Operator可以访问静态、const和类中重写的属性与方法。

(1)Program List:用变量在类定义外部访问

class Fruit {
  const CONST_VALUE = 'Fruit Color';
}
$classname = 'Fruit';
echo $classname::CONST_VALUE; // As of PHP 5.3.0
echo Fruit::CONST_VALUE;

(2)Program List:在类定义外部使用::

class Fruit {
  const CONST_VALUE = 'Fruit Color';
}
class Apple extends Fruit{
  public static $color = 'Red';
  public static function doubleColon() {
    echo parent::CONST_VALUE . "\n";
    echo self::$color . "\n";
  }
}
Apple::doubleColon();

(3)Program List:调用parent方法

class Fruit{
  protected function showColor() {
    echo "Fruit::showColor()\n";
  }
}
class Apple extends Fruit{
  // Override parent's definition
  public function showColor(){
    // But still call the parent function
    parent::showColor();
    echo "Apple::showColor()\n";
  }
}
$apple = new Apple();
$apple->showColor();

(4)Program List:使用作用域限定符

class Apple{
  public function showColor(){
    return $this->color;
  }
}
class Banana12{
  public $color;
  public function __construct(){
    $this->color = "Banana is yellow";
  }
  public function GetColor(){
    return Apple::showColor();
  }
}
$banana = new Banana;
echo $banana->GetColor();

(5)Program List:调用基类的方法

class Fruit{
  static function color(){
    return "color";
  }
  static function showColor(){
    echo "show " . self::color();
  }
}
class Apple extends Fruit{
  static function color(){
    return "red";
  }
}
Apple::showColor();
// output is "show color"!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
该资源内项目源码是个人的课程设计、毕业设计,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用! ## 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。 该资源内项目源码是个人的课程设计,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用! ## 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\DB; class WebModel extends Model { /** * Create a new Eloquent model instance. * * @param array $attributes */ public function __construct() { $this->setTable('pms_web'); parent::__construct(); } const STATUS_NORMAL = 1; //正常 const STATUS_FREEZE = 2; //冻结 public static function Enum($sign = "") { $status = [ 'status' => [ self::STATUS_NORMAL, self::STATUS_FREEZE ] ]; return isset($status[$sign]) ? $status[$sign] : $status; } public function WebDb() { return DB::table($this->getTable(),'w'); } public function FindOne($content, $param = "id") { $result = $this->WebDb()->where($param, $content)->select(DB::raw('id'))->first(); if (empty($result)) { return ''; } return $this->FormatOne($result); } public function FindList($params) { $query = $this->WebDb(); $query->select( DB::raw('SQL_CALC_FOUND_ROWS id') ); $query->limit($params['per_page']); $query->offset($params['offset']); $query->orderByDesc('w.id'); $result = $query->get(); $return_result = array( 'total' => 0, 'data' => [], ); if (empty($result)) { return $return_result; } $fromat_result = $this->FormatList($result); $total = DB::select("select FOUND_ROWS() as num")[0]->num; return [ 'total' => $total, 'data' => $fromat_result, ]; } public function FormatList(&$result) { foreach ($result as $v) { $this->FormatOne($v); } return $result; } public function FormatOne(&$result) { return $result; } public function simpleSave($data, $where = []) { } }
06-09

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值