last day (15 days later) » 

5:20 PM
0
Q: Custom error message when calling a function that doesn't exist in a class

William David EdwardsI have a class on GitHub (https://github.com/wdele/phplib) and I would like to output a custom error message if the specified class doesn't exist. Is this possible? For example: user tries to call function 123456 and it doesn't exist (main::123456()) and it doesn't exist, output the error messag...

 
Looks like a case for __call()
 
@kingkero I understand what it does, but it doesn't work. I just get a blank page.
 
Well, it works, the problem must be something else. Displaying errors shouldn't be your main concern, throwing an appropriate exception seems about right
 
@kingkero Do I need the try part?
 
That was only for demonstration purposes
 
5:20 PM
@kingkero OK, I understand. It doesn't work though: pastebin.com/i4WP8Wq5
Hi.
 
hello
the code you pasted has syntax errors in them
 
Such as...?
 
i think two missing }, so no big deal
pastebin.com/ph1ZqazJ this will work
the problem was that you MUST provide two arguments to __call()
 
Ahh!
Thanks a ton, it works now.
If you create an answer I'll accept it
 
Ok, let us delete the comments them
but one thing first
I think classes on github are usually named after the project name
 
5:23 PM
Correct, I will change it later
 
all right, glad it works now
 
Yep. Thanks!!
Thanks. See ya later :)
 

last day (15 days later) »