/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Assigning Method To Variable During Construction

Suppose I have the class definition below. As it is, it generates two “notices” and a “warning,” indicated in the // comments below.

[code=php]
class Error {
private $errorHandler;
private $exceptionHandler;

public function __construct() {
// the next two lines produce an undefined property “notice”
$this->errorHandler = $this->defaultErrHandler;
$this->exceptionHandler = $this->defaultExcepHandler;
// the call to set_error_handler() generates an invalid callback “warning”
set_error_handler($this->errorHandler);
set_exception_handler($this->exceptionHandler);
}
function __destruct() {
}
public function defaultErrHandler ($errno, $errmsg, $errfile, $errline) {
die(“Error #”.$errno.” ‘”.$errmsg.”‘ in path ‘”.$errfile.”‘ at line “.
$errline);
}
public function defaultExcepHandler ($exceptionInstance) {
die(“Exception #”.$exceptionInstance->getCode().” ‘”.
$exceptionInstance->getMessage().”‘ in path ‘”.
$exceptionInstance->getFile().”‘ at line “.$exceptionInstance->getLine());
}
}
[/code]

Should I be declaring the methods as static perhaps and then using static references [ self:: ]? What is ‘invalid’ about the callback…because it refers to an ‘undefined property’?

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogAug 07.2010 — How about...
[code=php]
class Error {
public function __construct() {
set_error_handler(array($this, 'defaultErrHandler'));
set_exception_handler(array($this, 'defaultExcepHandler'));
}
function __destruct() {
}
public function defaultErrHandler ($errno, $errmsg, $errfile, $errline) {
die("Error #".$errno." '".$errmsg."' in path '".$errfile."' at line ".
$errline);
}
public function defaultExcepHandler ($exceptionInstance) {
die("Exception #".$exceptionInstance->getCode()." '".
$exceptionInstance->getMessage()."' in path '".
$exceptionInstance->getFile()."' at line ".$exceptionInstance->getLine());
}
}
[/code]
×

Success!

Help @seniseven spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...