Using dynamic objects in PHP (7.4), PhpStorm was throwing up warnings whenever a method was called on the resulting object. Hinting in a comment cured that (also, for methods that return objects, specifying the object type in a PHPDoc comment for the method).
Eliminates the PhpStorm warning: Method 'methodname' not found in ... Referenced method not found in subject class
Eliminates the PhpStorm warning: Method 'methodname' not found in ... Referenced method not found in subject class
/**
* Inserts new data into database, returns object representing the newly inserted row. If table has a single primary key column and
* that column value is not defined in $data[], insert() will generate it using the method specified in newPrimaryKeyCallbackFunction
* If has_a is specified, an object of the appropriate type can be passed for that column
*
*
* @param String[] $data Associative array; keys match up to the database table columns, values are initial settings for those fields.
*
* @see setPrimaryKeyCallback()
* @throws Exception If something interesting cannot happen
* @return ClassDBI (subclass, e.g., Author)
*/
public static function insert( $insdata = null ) {
$ocname = get_called_class();
// $data = array();
// if(func_num_args() == 1 && $insdata !== null) {
// $data = $insdata; // Create new database row with passed data
// } else {
// $data = $this->rowdata; // Create new database row with data already populated
// }
$data = $insdata;
// print "insert() called from an instance of $ocname\n"; // debug
/* @var $obj ClassDBI */ // Eliminates "method 'primaryKey not found in ... Referenced method not found in subject class." warning in PhpStorm
$obj = new $ocname();
// print "object instantiated: " . print_r($obj); // debug
$pk = $obj->primaryKey();
Comments
Post a Comment