Book a Demo

Author Topic: Using PHP Type Hints and docblocks on Source Code Engineering  (Read 2713 times)

Matthias Pigulla

  • EA Novice
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Hi all,

as you might know, PHP is a weakly typed and dynamically binding language. This makes it especially hard for IDEs and tools to come up with  good code completion suggestions or "code insight" features.

For example NuSphere's PhpEd or Zend's Studio are interpreting docblock comments to work around that.

Now Enterprise Architect can already make use of PHP5 type hints when reverse engineering source code; it would be nice if that could be extended to use the same docblock hints.

Example:

<?php

class A  {}
class C {}

class B extends A {

      /** @var C Some comment... */ protected $aProtectedC;
      
      /**
      * @param A $bar Some instance of A.
      * @param int $b Some parameter.
      * @return C Some comment...
      */
      public function aPublicMethod(A $bar, $b) { }

}


?>

Class B has a protected field of type C - not guaranteed nor checked by the language, but a reasonable assumption ;). Similarly, the public method expects parameter 1 to be of type A (a runtime-checked type hint). The second parameter can technically be of any type, but should be considered as int. Here 'int' is a hint how the parameter is going to be interpreted or used.

As many developers using PHP IDEs have these hints in place it would be nice if EA could make use of them as well.

More information regarding possible comments can be found here:

http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_tags.pkg.html

Thoughts?