本文介绍了扩展PHP的类型提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Netbeans中使用另一个documentor标签扩展类型提示?

Is it possible to extend the type-hinting with another documentor tag in Netbeans?

我正在寻找一种使用@scope标记扩展类型提示的方法,该标记将允许所包含的文件访问对象范围.

I'm looking for a way to extend the type-hinting with a @scope tag that would allow for includeed files to gain access to an objects scope.

示例:

file: template.php
<?php /* @var $this MyObject */

这仅允许对公共变量和方法进行类型提示.我希望做的是使用@scope标记扩展类型提示,使其能够访问MyObject范围:

This would only allow for type-hinting of public variables and methods. What I'm hoping to do is to extend type-hinting with the @scope tag allowing it to gain access to the MyObject scope:

file: template.php
<?php /* @scope MyObject */

这将使文件内容的行为类似于在MyObject范围内,而$this会提示私有方法.

Which would make the file content to act like it would be in the MyObject scope and $this would hint private methods.

现在,我没有为Netbeans平台开发的经验,但是我有Java的经验.如果我想做到这一点,我应该从哪里开始?

Now, I have no experience in developing for the Netbeans platform but I have Java experience. If I wanted to accomplish this, where would I start?

希望这不是一个太弱的问题.

Hopefully this is not too weak of a question.

推荐答案

在过去(NetBeans的较旧版本)中,类型提示显示的是类(正在使用其对象)中的所有方法,即所有public ,受保护的,私有的甚至是静态方法.现在,在NetBeans的新版本中,此 bug 已修复,当在对象上进行类型提示时,仅可访问的方法/属性被类型提示.

In the past (older versions of NetBeans) the type-hinting was showing all the methods from a class (of which object was in use), i.e. all public, protected, private and even static methods. Now, in new releases of NetBeans, this bug was fixed and when type-hinting on the object only the accessible methods/properties are type-hinted.

这仅仅是因为您的模板无法访问/调用类的私有属性/方法,以及是否有对象(类的实例),您不应该能够访问/调用其类的静态属性/方法.

This is simply just because Your template cannot access/call private property/method of a class as well as if You have an object (instance of a class) You shouldn't be able to access/call it's class's static properties/methods.

如果您愿意在类内部键入提示,则同样适用-现在,键入提示列出了$this->|(|是光标)的所有公共,受保护和私有方法,而静态属性和方法仍未列出.另一方面,如果您在MyClass::|上键入提示,则现在仅列出静态属性/方法,并且再次在 MyClass 类中列出所有公共属性,受保护属性和公共属性,而当从外部访问时,列表中的(非常正确)丢失了.

The same applies if You are willing to type-hint inside of the class - now the type-hinting lists all the public, protected and private methods for $this->| (| is the cursor) while the static properties and methods are still not listed. On the other side, if You are type-hint on MyClass::| now only the static properties/methods are listed and again, when inside the MyClass class all the public, protected and public ones are listed while when accessing from outside the private ones are (very correctly) missing in the list.

因此,您所要求的功能是错误的,并且拒绝正确的封装原理.

So the functionality You are requesting is wrong and denies the correct principles of encapsulation.

这篇关于扩展PHP的类型提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 06:21