Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extending type-hinting for PHP

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

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.

Example:

file: template.php
<?php /* @var $this 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 */

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

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.

like image 503
Daniel Avatar asked Jan 10 '13 10:01

Daniel


People also ask

Should I use type hinting in PHP?

Apparently 'type hinting' in PHP can be defined as follows: "Type hinting" forces you to only pass objects of a particular type. This prevents you from passing incompatible values, and creates a standard if you're working with a team etc.

What is type hinting in PHP with example?

Type hinting is a concept that provides hints to function for the expected data type of arguments. For example, If we want to add an integer while writing the add function, we had mentioned the data type (integer in this case) of the parameter.

Which data types can be declared with type hinting in PHP?

In simple word, type hinting means providing hints to function to only accept the given data type. In technical word we can say that Type Hinting is method by which we can force function to accept the desired data type. In PHP, we can use type hinting for Object, Array and callable data type.

Which PHP type hinting was introduced?

Type Hinting was introduced in which version of PHP? Explanation: PHP 5 introduced the feature of type hinting.


1 Answers

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.

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.

like image 75
shadyyx Avatar answered Oct 21 '22 17:10

shadyyx