编程语言
首页 > 编程语言> > PHP对象及其功能

PHP对象及其功能

作者:互联网

我现在使用的是PHP 5,我很乐意在PHP 5中使用OOP.我遇到了一个问题.我里面的课程很少,功能很少.很少有函数需要传递参数,这些参数是我自己写的那些类的对象.我注意到,参数不是严格打字的.有没有办法让它严格打字,以便在编译时我可以使用Intellisense?

例:

class Test
{
   public $IsTested;

   public function Testify($test)
   {
      //I can access like $test->$IsTested but this is what not IDE getting it
      //I would love to type $test-> only and IDE will list me available options including $IsTested
   }
}

解决方法:

好吧,你可以用type hinting做你想做的事:

public function Testify(Test $test) {

}

要么是,要么是docblock:

/**
 * @param Test $test The test to run
 */

这取决于IDE,以及它如何获取类型提示……我知道NetBeans足够聪明,可以选择类型提示Testify(Test $test)并让你从那里开始,但其他一些IDE并不是那很聪明……所以这真的取决于你的IDE哪个答案会让你自动完成…

标签:php,type-safety
来源: https://codeday.me/bug/20190621/1257221.html