[ create a new paste ] login | about

Link: http://codepad.org/HHaVoXrc    [ raw code | output | fork ]

PHP, pasted on Oct 29:
<?php
$ok = true;

function foo($first, &$second = null) {
    global $ok;
    
    if (!is_null($second)) { // <-- You're supposed to change this line
                             // if (func_num_args() == 2) works, but am wondering
                             // if there are better methods that deal directly with $second
                             // in case the function signature changes.

        if ($first == 'a') {
            $ok = false;
            echo "Failed: This should not be triggering for Call A.\n";
        }
        $second = 'world';
    }
}

// Call A
foo('a');

// Call B
foo('b', $test);

if ($test !== 'world') {
    $ok = false;
    echo "Failed: \$test should be assigned.\n";
}

if ($ok) {
    echo "Success. Please share your solution.\n";
}


Output:
1
Failed: $test should be assigned.


Create a new paste based on this one


Comments: