This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 194313 - Resolve typing could go through constructors to find out types of properties
Summary: Resolve typing could go through constructors to find out types of properties
Status: RESOLVED FIXED
Alias: None
Product: php
Classification: Unclassified
Component: Code (show other bugs)
Version: 6.x
Hardware: PC Windows 7
: P2 normal (vote)
Assignee: Petr Pisl
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-13 16:18 UTC by daftspider
Modified: 2011-01-17 16:32 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description daftspider 2011-01-13 16:18:15 UTC
See That code:

DataBase.php:
<?php
class DataBase {
    private $link;

    public function __construct($host, $username, $password, $dbName){
        $this->link = mysql_connect($host, $username, $password);
        mysql_select_db($dbName, $this->link);
    }

    public function exec($query){
        $result = mysql_query($query, $this->link);
        if(is_bool($result)){
            return $result;
        }else{
            $all = array();
            while($all[] = mysql_fetch_array($result, MYSQL_ASSOC)){}
            mysql_free_result($result);
            return $all;
        }
    }

    public function close(){
        mysql_close($this->link);
    }
}
?>

Model.php:
<?php
include 'DataBase.php';

class Model {
    protected $db;

    public function __construct(){
        $this->db = new DataBase("localhost", "root", "root", "MyDB");
    }
}
?>

IndexModel.php:
<?php
include 'Model.php';

class IndexModel extends Model{

    function  __construct() {
        parent::__construct();
    }

    public function get(){
         $this->db->exec("SELECT * FROM users");
    }
}
?>

------------------------------------------------------------------------------

Parser don't see any methods of $this->db in class 'IndexModel' that extends 'Model', test it and fix this bug.
This code works fine.
Comment 1 Petr Pisl 2011-01-17 13:36:15 UTC
Unfortunately we are not able to recognized that the $db has type Database, because is defined in constructor. You have to use phpdoc to help NetBeans to know abou the type. So write:

class Model {
    /**
     *
     * @var DataBase
     */
    protected $db;

and it will work correctly. 


I'm switching this issue to the enhancement, to remember that it can be resolve typing extended to the constructors.
Comment 2 Petr Pisl 2011-01-17 16:32:32 UTC
I have looked at issue #194300. The constructor scanning for resolving type was already implemented, but was broken. Now this case should as well. Fixed in webmain clone.