Let's say I have two classes. One is a simple data access object, with a number of methods which interact with the database, e.g.
Code: Select all
<?php
class UserDA {
// assume here we set UserDA::db to point to a singleton instance of DB_ADODB (see below)
// this accepts an object of type User (an object holding row data for a single database record, and getter methods)
public function create(User $user) {
$this->db->exec(__LINE__,__FILE__,"insert into table_users (name, address) values ('".$user->getName()."','".$user->getAddress()."')");
}
}
?>Code: Select all
<?php
class DB_ADODB {
// assume up here we set a DB_ADODB::dbA property to reference a ADODB object
public function exec($line, $file, $sql, $conf=null) {
$result = $this->dbA->Execute($sql);
if(!$result) {
die("Query failed on line $line of $file.");
}
}
}
?>In the above I'm passing the line number and filename of exactly where a SQL call is made in the UserDA class. The idea being that if an error occurs, the application will die, and output a message telling me exactly where the SQL query responsible for the error occured. (Forgive any obvious shortcomings in the above - it's a simple case ignoring stuff like mysql error strings, etc.)
My question is whether there exists a method of capturing these __LINE__, __FILE__ values to pass to any subsequent message generated by another method, in another class - but without passing them through the function.
If you follow my logic, you wind up passing them with every method call to the DB_ADODB class - call me a lazy typist
Just might be there is no other way, and this is a wasted post... If so I'm hunting whoever mentioned an alternative exists and make them eat their socks...