re: What language features/concepts do insiders of the language love and outsiders hate? VIEW POST


For PHP the way isn't (wasn't) very type strict, and you could implement your own handle logic, based on method return value:

$result = $myClass->save();

if (is_array($result)) {
    // Validation errors!
    // Warnings are returned in structured array, where indexes are class attributes
    // Example:
    // $result['firstname'] = 'First name is required'
    // $result['email'] = 'Email address must be valid' 
} elseif (is_numeric($result)) {
    // New record created!
    // Method returns newly created database row ID
} else {
    // Record updated!
    // Method returns TRUE

I have to admit I've kind of converted to returning TRUE or FALSE, and implementing another method to get errors, if save failed using $errors = $myClass->getErrors(), but it was still nice shortcut, purely because PHP didn't enforce explicit return types.

code of conduct - report abuse