drd0833 2017-09-18 21:31 采纳率: 100%
浏览 56
已采纳

方法中的类名和变量

I am reading about design patterns in PHP and I keep seeing the following syntax, for example

abstract class AbstractObserver {
    abstract function update(AbstractSubject $subject_in);
}

or

class PatternObserver extends AbstractObserver {
    public function __construct() {
    }
    public function update(AbstractSubject $subject) {   
    }
}

(code is part of this example)

where "AbstractSubject" is another abstract class.

I am used to defining methods like methodName($var), not including a class name in there, like methodName(className $var).

So, what actually the class name does in a method ? My best guess is that it passes something like a reference in that class? Can you explain to me what it actually does?

Thanks

  • 写回答

1条回答 默认 最新

  • doupao1530 2017-09-18 21:35
    关注

    It's called Type Hinting, since php 7 you can use scalar types to type hint parameters. (Some more)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 找一个QT页面+目标识别(行人检测)的开源项目
  • ¥15 有没有整苹果智能分拣线上图像数据
  • ¥20 有没有人会这个东西的
  • ¥15 cfx考虑调整“enforce system memory limit”参数的设置
  • ¥30 航迹分离,航迹增强,误差分析
  • ¥15 Chrome Manifest扩展引用Ajax-hook库拦截请求失败
  • ¥15 用Ros中的Topic通讯方式控制小乌龟的速度,走矩形;编写订阅器代码
  • ¥15 LLM accuracy检测
  • ¥15 pycharm添加远程解释器报错
  • ¥15 如何让子窗口鼠标滚动独立,不要传递消息给主窗口