why possible create interface without specifying return type? why doesn't make interface unusable?
this makes more clear:
interface run { public function getinteger(); } class mystring implements run { public function mynumber() { } public function getinteger() { return "not number"; } } in java every interface has return type integer, string or void
i know php unfortunately loosely typed language isn't there solution problem?
is possible define interface return type integer?
type hinting function/method arguments or return values supported @ php7.0 or later
check details here: http://php.net/manual/en/migration70.new-features.php
if using php5 current accepted practice use phpdoc comments indicate "contract" present.
/** * something. * @return int **/ public function getinteger() { return 1; } if code violates "contract," suggest finding original coder , having them fix and/or filing bug and/or fixing if it's in own codebase.
Comments
Post a Comment