php - Multiple return types of in a method? -
php - Multiple return types of in a method? -
i have rule class has check($input)
method returns boolean true
if input valid or returns string error message when invalid. , because in php can't specify homecoming type when declaring functions (like in java example), can homecoming whatever.
is best practice have method or variable return/contain 1 value type? e.g. boolean
, string
, or integer
.
usually when i'm implementing interface, 1 homecoming type expected each of methods.
that allright of php functions have multiple homecoming type. illustration strpos() function
it homecoming number if worked correctly , homecoming boolean false if not work expected
however , gordonm said , multiple homecoming type may confuse when seek check wheater worked correctly or not. in general , multiple homecoming allright php functions.
php return return-value return-type
Comments
Post a Comment