I have no clue how to phrase this question in a search engine.
I'm a bit confuse how classes use other class's methods without include/require. I've seen this in PHP a couple of time now. Coming from C++ background, I had to include everything in order to use it, so it's a bit confusing.
But ok here we go:
Say i have improve_db_connection.php:
class improve_db_connection
{
protected $_connection;
public function __construct($host, $user, $pwd, $db)
{
$this->_connection = @new mysqli($host, $user, $pwd, $db);
if (mysqli_connect_error()) {
throw new RuntimeException('Cannot access database: ' .
mysqli_connect_error());
}
}
public function getResultSet($sql)
{
$results = new Pos_MysqlImprovedResult($sql, $this->_connection);
return $results;
}
}
The new Pos_MysqlImprovedResult is an instance of Pos_MysqlImprovedResult class, not improve_db_connection. Without declaring the include function to include the class Pos_MysqlImproveResult, the improve_db_connection.php file just knows where the class is.
Is it because the Pos_MysqlImproveResult.php is in the same directory as improve_db_connection.php?
It's the same thing with Zend Framework. But the files are in subdirectories and such. I have a class in application/modules/SF/models that uses another class function that is in application/modules/SF/models/resources. Is it because the Zend naming convention of these classes that Zend just parse through these files and add it into the php's __autoload?
Thank you in advance.