P
P
Pavel Volintsev2013-09-01 19:08:14
PHP
Pavel Volintsev, 2013-09-01 19:08:14

$this in PHP template engine

There is a page - a template on purePHP
It is drawn by inclusion in some class method

<?php
class SomeClass {

     public function count() { return 0; }
}

class OtherClass {

   /**
    * @var SomeClass
    */
   protected $var1;

   function __construct() {
      $this->var1 = new SomeClass;
   }

   function showCount() {
       include('showCount.phtml');
   }
}


$x = new OtherClass;
$x->showCount();

?>


The showCount.phtml file contains the following content
<?php

// note : $this instanceof OtherClass
echo $this->var1->count();

?>


Question: How can I help the IDE enable Code Completion inside the showCount.phtml file for the $this variable, which in this context is an entity of the OtherClass class?




My option is this:
<?php

/**
 * @var OtherClass
 */
$that = $this;

echo $that->var1->count(); // подсказки работают
?>

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
EugeneOZ, 2013-09-01
@copist

Try

@var OtherClass $this

A
Andrey Shiryaev, 2013-09-01
@Claud

So, and what's wrong with this option, I use it myself.

L
LastDragon, 2013-09-01
@LastDragon

Question: How can I help the IDE enable Code Completition

Generally depends on the IDE, Eclipse and NetBeans understand:
/* @var $name \class\name */

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question