I've tried to delete the possibly empty last entry of an array as follows but I get the error: "Can't use function return value in write context":
if (empty(end($crontabEntryList))) {
array_pop($crontabEntryList);
}
If I first assign end's return value to a variable (as at the bottom) I am able to delete that last entry if empty. Per the manual entry for end() it "returns the value of the last element or FALSE for empty array." Through googling I've found a possible explanation: booleans are not "writable".
However then it would seem that this error gets returned, in my specific context, and possibly others documented here on SO, merely because it is possible that a boolean could be returned. Because, the array in my instance decidedly was not empty, and therefore rather than false, end() "returns the value of the last element".
Are my assumptions correct? In which case, isn't this inconsistent with the loosely typed nature of PHP? Or is it because the last element of the array is "not writable"? In which case, what precisely constitutes "write context" in PHP?
$last = end($crontabEntryList);
if (empty($last)) {
array_pop($crontabEntryList);
}