Possibly Related:
Why don't PHP attributes allow functions?
Pardon me if this has been asked before, but why can you not have something like the following:
class foo {
require_once 'defines.php';
private $_server = DB_SERVER;
private $_username = DB_USERNAME;
private $_password = DB_PASSWORD;
private $_database = DB_NAME;
public $debug = false;
public $_conn;
function __construct() {
$connection = @mysqli_connect($this->_server, $this->_username, $this->_password, $this->_database);
}
...
}
Cheers,
EDIT: Looking to find out why this behaviour exists and why its not possible. How come the votes to close?
EDIT2 : Would also like to re-open this
require_once
is a dependency (on the availability of the file, etc.) that doesn't belong in a blueprint. But I see what you mean - this would be handy to have sometimes. – Correctionrequire_*
andinclude_*
are language constructs and not functions. – Correctioninclude is not allowed here
:| – Correctioninclude()
– Correctiondefines.php
was really given. @OP, You may want to look into extending the class and have a main class if you plan on using this a lot. I know you were not looking for solutions, but oh well :) – Stewartrequire
is not a function. – Hardiness