SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: How to have PHP kill a script upon a function call without necessary arguments?

  1. #1
    ¿uʍop ǝpısdn ʎɥʍ velocd's Avatar
    Join Date
    Aug 2002
    Location
    California
    Posts
    449
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to have PHP kill a script upon a function call without necessary arguments?

    In simple terms, take this function:

    PHP Code:
    function my_function($foo$stuff)
    {
        echo 
    'good';

    If I execute this function without any of the parameters, which as you can see don't have default values, PHP will throw an error at me--but continue to execute the script.

    How can I change this behavior to have PHP kill the script?

    Yes, I could add into the function something like:

    PHP Code:
    if (!$foo || !$stuff)
    {
        exit;

    But.. I'm sure there is a PHP environment setting or the like to control it.

    Thanks in advance if you can help.

  2. #2
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,522
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think what you want is something like this:
    Code:
    if (!isset($foo) || !isset($stuff)) 
    { 
        exit; 
    }
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  3. #3
    SitePoint Enthusiast thor@iway.na's Avatar
    Join Date
    Sep 2003
    Location
    Namibia
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could use the
    PHP Code:
    die; 
    statement and print an error with it when the script execution dies right then and there e.g.
    PHP Code:
    function myfunc($foo$zoo) {
        if(!isset(
    $foo || !isset($zoo){
            die(
    'Invalid arguments passed!');
        } else {
            
    //your other code here...
        
    }

    There is no spoon

  4. #4
    ¿uʍop ǝpısdn ʎɥʍ velocd's Avatar
    Join Date
    Aug 2002
    Location
    California
    Posts
    449
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm aware of those methods, but I was hoping for a quick solution, a php.ini setting or the sort, instead of having to embed error checking code in each of my custom functions (I've got more than 30 of 'em).

    Hm.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •