<?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";
}