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

Bug 322503

Summary: Type Hinting does not work when using $this
Product: z_Archived Reporter: Sebastian Kübbeler <sebastian.kuebbeler>
Component: PDTAssignee: Zhongwei Zhao <zhaozhongwei>
Status: CLOSED WORKSFORME QA Contact:
Severity: enhancement    
Priority: P3 CC: ganoro, silviya, wywrzal, zhaozhongwei, zulus
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Sebastian Kübbeler CLA 2010-08-12 07:00:45 EDT
Build Identifier: 20100617-1415

When trying to use Type Hinting on object variables, hints are not resolved when referencing the variable using $this.

Reproducible: Always

Steps to Reproduce:
Here a dumbed down version of a CodeIgniter Controller to illustrate:

class Case_Status_Report {

	/* @var $caseStatus Case_Status_Model */
	private $caseStatus;

	function index() {
		$this->load->model('Case_Status_Model', 'caseStatus');
		/* @var $this->caseStatus Case_Status_Model */
		$this->caseStatus->"this is not type aware"
	}
}
Comment 1 Zhongwei Zhao CLA 2010-08-12 07:43:32 EDT
after I tried:
$caseStatus->| //"this is not type aware too!"
Comment 2 Sebastian Kübbeler CLA 2010-08-12 07:51:01 EDT
// This is type aware though. Probably due to the assignment.
/* @var $caseStatus Case_Status_Model */
$caseStatus = $this->load->model('Case_Status_Model');
$data = $caseStatus->getOpenCases();
Comment 3 Sebastian Kübbeler CLA 2010-08-12 07:53:16 EDT
Oh and I am sorry, but without the Case_Status_Model Class this can't be type aware. You can write your own dummy for testing or use my original:

class Case_Status_Model extends Model {

    function Case_Status_Model() {
        parent::Model();
        $this->load->database();
    }

    function getNewCases () {
        // do something
    }
}
Comment 4 Zhongwei Zhao CLA 2010-08-12 08:28:24 EDT
Hi,

Sorry now I understand the bug,thanks for your explanation!
Comment 5 Zhongwei Zhao CLA 2011-06-30 02:21:43 EDT
hi,

you should change:

/* @var $caseStatus Case_Status_Model */
private $caseStatus;

to

   /** 
    * @var Case_Status_Model 
    * */
   private $caseStatus;
Comment 6 Dawid Pakula CLA 2014-02-18 19:45:11 EST
What's now with this issue?
Is still active? 

As I see, Sebastian isn't using phpDoc.
Comment 7 Michal Niewrzal CLA 2015-01-05 07:05:04 EST
I think main problem is that phpDoc was incorrectly used for field declaration. Second problem was that inline @var tag is not working for structure like "$this->caseStatus", but in my opinion it shouldn't work (user must use valid phpDoc @var tag).

<?php
class Case_Status_Model {
	public function test() {
	}
}
class Case_Status_Report {
	
	private $caseStatus;
	
	function index() {
		$this->load->model ( 'Case_Status_Model', 'caseStatus' );
		/* @var $this->caseStatus Case_Status_Model */
		$this->caseStatus->| // something like this is not working
	}
}

Something like this is working well:
<?php
class Case_Status_Model {
	public function test() {
	}
}
class Case_Status_Report {
	
	/**
	 * 
	 * @var Case_Status_Model
	 */
	private $caseStatus;
	
	function index() {
		$this->load->model ( 'Case_Status_Model', 'caseStatus' );
		$this->caseStatus->| // works ok
	}
}

If someone disagree please reopen bug:)
Comment 8 Sylvia Tancheva CLA 2015-01-14 09:58:27 EST
Closing