I have two functions, which take a parameter.

The way my script works is that it retrieves some data as a string. This string can be in two formats, which is unkown to me and cannot be obtained beforehand. 

So i have 2 functions, one for each type of format.

Function 1 is first called, with the string passed as a parameter. I then check if a variable within this function has been assigned. If the variable has been assigned, it means the string format was recognised. If the variable has not been assigned, function 2 is then called with the same parameter. This should work.

The problem is that when I run the script, say if function1 works, then I get undefined variable errors for function 2. I don't understand why this is the case, as it has not been called yet and therefore should not have been processed/looked at. 

Is there a way I can only make a function available when it is called?

```
recurrence_info_day($eventtype);
$recurrence_type = "daily";
if (!$eventstart){
   recurrence_info_weekly($eventtype);
   $recurrence_type = "weekly";
}

function recurrence_info_day($eventtype){
    $s = $eventtype;    
    preg_match('/^DTSTART;VALUE=DATE:(\d+)\s+DTEND;VALUE=DATE:(\d+)\s+RRULE:FREQ=(\w+);INTERVAL=(\d+);UNTIL=(\d+)/', $s, $recinfod);
    $eventstart = $recinfod[1];
    $eventend = $recinfod[2];
    $eventfrequency = $recinfod[3];
    $eventinterval = $recinfod[4];
    $eventuntil = $recinfod[5];

    $formstartdate = substr($eventstart,4,2)."/".substr($eventstart, 6)."/".substr($eventstart,0,4);
    $formenddate = substr($eventuntil,4,2)."/".substr($eventuntil, 6)."/".substr($eventuntil,0,4);
}

function recurrence_info_weekly($eventtype){
    $s = $eventtype;
    preg_match('/^DTSTART;VALUE=DATE:(\d+)\s+DTEND;VALUE=DATE:(\d+)\sRRULE:FREQ=(\w+);BYDAY=(\d+);UNTIL=(\d+)/', $s, $recinfow);
    $eventstart = $recinfow[1];
    $eventend = $recinfow[2];
    $eventfrequency = $recinfow[3];
    $eventdays = $recinfow[4];
    $eventuntil = $recinfow[5];

    $formstartdate = substr($eventstart,4,2)."/".substr($eventstart, 6)."/".substr($eventstart,0,4);
    $formenddate = substr($eventuntil,4,2)."/".substr($eventuntil, 6)."/".substr($eventuntil,0,4);
}

```