Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 240469

Summary: Allow code assist type hinting for templates in other files
Product: z_Archived Reporter: ChanibaL <eclipse.org>
Component: PDTAssignee: Roy Ganor <ganoro>
Status: CLOSED FIXED QA Contact: Sylvia Tancheva <silviya>
Severity: enhancement    
Priority: P3 CC: eclipse.org, exceptione, gadi, spektom
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description ChanibaL CLA 2008-07-11 06:51:28 EDT
Hi, this should be an easy fix, I think. 
Many people (including me) make templates like this:

--- ClassNeedingATemplate.php ---
<?php
  class ClassNeedingATemplate extends SomeMoreBasicOne {
    protected $title;
    protected $body;

    public function __construct() {
      // some logic hydrating the $this->title and $this->body
    }

    public function display() {
      require 'template.php';
    }

    public function where_type_hinting_works_but_an_external_template_is_better() {
      ?>    
      <div>
      <h1><?=$this->title?></h1>
      <?=$this->body?>
      <div>
      <?php
    }

  }
?>
--- tempate.php ---
<?php 
  /* @var $this ClassNeedingATemplate */ 
?>
<div>
  <h1><?=$this->title?></h1>
  <?=$this->body?>
<div>
---

The type hinting for $this works this way, but in the external file it sees the class as from the outer scope, so it only sees the public members of it.

A var named $this could be made a special case of type hinting where it gives the full access to type hinting from the class.

Problem exists in PDT 1.0.3 (why isn't this version listed here anyway?)
Comment 1 ChanibaL CLA 2008-07-11 06:56:37 EDT
Also exists in 2.0.0 (org.eclipse.php_feature-I20080707.zip)
Comment 2 Michael Spector CLA 2009-01-08 03:49:54 EST

*** This bug has been marked as a duplicate of bug 260330 ***
Comment 3 ChanibaL CLA 2009-01-08 09:21:05 EST
No this is not a duplicate, one of the things to make this work is broken because of that bug, but this itself is a feature request to be able to use some PHP specyfics - including files inside class instances preserving the scope.

To sum up it's using /* @var $this TheClass */ to type hint it's the public/private/protected scope, not just public as it would be outside.
Comment 4 exceptione CLA 2009-01-19 11:26:09 EST
(In reply to comment #3)
> No this is not a duplicate, one of the things to make this work is broken
> because of that bug, but this itself is a feature request to be able to use
> some PHP specyfics - including files inside class instances preserving the
> scope.
> 
> To sum up it's using /* @var $this TheClass */ to type hint it's the
> public/private/protected scope, not just public as it would be outside.
> 

You're right, this is not a duplicate. What you're asking for is that for inline docblocs (/* @var $this TheClass */) $this should not only be typed as TheClass , but that the identifier $this should have the class internal scope.
You're right here. I suggest that for inline docblocks involving $this, the scope should be widened to the class internals.

Comment 5 Michael Spector CLA 2009-05-08 18:09:07 EDT
Use: /* @var $variableName ClassName */
The original bug (260330) was fixed in CVS.

*** This bug has been marked as a duplicate of bug 260330 ***
Comment 6 Gadi Goldbarg CLA 2010-01-21 06:42:05 EST
Using the sample code given by the reporter works as expected.
Code Assist is given for $this when /* @var $this ClassNeedingATemplate */ is used.
Closing the bug.
[Sylvia Tancheva]