views:

15

answers:

1

Hello everyone, In PHP I allow the user to enter a url and load a file, function, parameters accordingly with a simple routing file.

A Url of http://localhost/user/edit/1 will call the file user.php and the function edit() inside it and pass the parameter 1 to it. If the user removed the argument 1 and the preceeding slash so a function missing argument error will appear which I don't like. I tried exception handling like this.

<?php
try {
 call_user_func($action,$params);
} catch (Exception $e) {
 echo "You followed a wrong URL to get to this page";
}
?>



but this doesn't work and the php warning will appear. How can I hide this ?

+1  A: 

make edit() throw an exception if the passed argument is null.

mwhite