Question

How can code completion occur with phpDoc blocks loaded using the T_OBJECT_OPERATOR without having to preset the variables as is shown is the source below?

The only class that matters is the parentExample as it set's the needed $cc that does offer a working solution but it is not desired to preset variables in this manner.

The example code shows the undesired solution and multiple non-working attempts.

As code completion is based on previously set information, preferred to use the full example script not just pieces. Also, as it does relate to phpDocumentor basic phpDoc blocks were included as well. It is desired that these docBlocks get loaded as part of the code completion not just named objects.

<?php
/**
 * This is a parent class.
 * 
 * @package Examples/doubledVars
 */
class parentExample 
{   
    /* @var $a parentExample */
    public $a;

    /**
     * This is a var named b
     * @var $b parentExample
     */
    public $b;

    public $c;
    public $cc;
    // notice^ <------------------------------------------------------SEE ME

    /**
     * A basic contructor
     */
    public function __construct() 
    { 
        echo '::PE Class initiated::'; 

        $this -> a = 'we are value "a" in the parent class'; 
        $this -> b = 'we are value "b"  in the parent class'; 
        $this -> c = 'we are value "c"  in the parent class'; 
    }
} 

/**
 * This is an Example of doubling occuring due to failed to __construct()
 * 
 * @package Examples/doubledVars
 */
class doubledVars extends parentExample 
{   
    /**
     * Value is obtained via parent constuctor.
     * 
     * @return string assigned during construction of parent class.
     */
    public function getA() 
    { 
        return $this -> a; 
    } 
}

/**
 * This is an Example of no doubling occuring due to __construct()
 * 
 * @package Examples/doubledVars
 */
class noDouble extends parentExample 
{  
    /**
     * an empty constructor used to prevent doubling during construction.
     * child class makes use of parent constructor unless it has it's own.
     * or none exsist.
     */
    public function __construct() 
    { 

    } 

    /**
     * Empty string return
     * 
     * Shows an example of returning values set based on the constructor 
     * class. In this case there is no default values set at any point, but
     * rather value is assigned during the construction of a object.
     * 
     * @return string This string is empty
     */
    public function getB() 
    { 
        return $this -> b; 
    } 
} 

/**
 * This is an Example of no doubling occuring due to __construct()
 * @see noDouble
 * 
 * @package Examples/codeCompletion
 */
class codeCompletion extends parentExample 
{  
    /**
     * @see noDouble::__construct()
     */
    public function __construct() 
    { 
        //empty constructor prevents doubling
    }


    public function getC() 
    { 
        return $this -> c; 
    } 
}


/** @var $parentExampleDV parentExample */
$parentExampleDV = new parentExample;

// Tried this for Code completion, it did not work <------------------SEE ME
/** @var $doubledVars doubledVars */
$parentExampleDV->doubledVars = new doubledVars; 

/* output on next 'echo' will be as follows */
//::PE Class initiated::::PE Class initiated::we are in the parent class
echo '@@'.$parentExampleDV->doubledVars->getA().'@@';// NO CC <-------SEE ME

echo '<br><br>----------<br><br>';


/** @var $parentExampleDV parentExample */
$parentExampleND = new parentExample;

// Tried this for Code completion, it did not work <------------------SEE ME
/** @var $parentExample->noDouble noDouble */
$parentExampleND -> noDouble = new noDouble;

/* output on next 'echo' will be as follows */
//we are in the parent class
echo '!!'.$parentExampleND->noDouble->getB().'!!';// NO CC <----------SEE ME

echo '<br><br>----------<br><br>';

$parentExampleCC = new parentExample;

$parentExampleCC->cc = new codeCompletion;

echo '##'.$parentExampleCC->cc->getC().'##';//CC working <------------SEE ME

echo '<br><br>----------<br><br>';
Was it helpful?

Solution

I guess It is not possible at this time...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top