note 119762 added to language.oop5.overloading

From: Date: Fri, 19 Aug 2016 14:23:57 +0000
Subject: note 119762 added to language.oop5.overloading
Groups: php.notes 
Request: Send a blank email to php-notes+get-206323@lists.php.net to get a copy of this message
This "overloading" perspective increases complexity and can have unintended consequences. A better solution than to use is to create your own overloading handlers. For example <?php function service( int $one = null, int $two = null, int $three = null ) { if( null === $one && null === $two && null === $three ) { serviceEmpty(); } else if( null !== $one && null === $two && null === $three ) { serviceOne( $one ); } else if( null !== $one && null !== $two && null === $three ) { serviceTwo( $one, $two ); } else if( null !== $one && null !== $two && null !== $three ) { serviceThree( $one, $two, $three ); } } ?> This makes one function service as three functions in a similar style as overloading in other programming languages. Then the use would be like this: <?php service( 'Hello' ); service( 'world!', 'Hey' ); service( 'you', 'out', 'there.' ); ?> ---- Server IP: 72.52.91.14 Probable Submitter: 12.165.112.61 ---- Manual Page -- http://php.net/manual/en/language.oop5.overloading.php Edit -- https://master.php.net/note/edit/119762 Del: integrated -- https://master.php.net/note/delete/119762/integrated Del: useless -- https://master.php.net/note/delete/119762/useless Del: bad code -- https://master.php.net/note/delete/119762/bad+code Del: spam -- https://master.php.net/note/delete/119762/spam Del: non-english -- https://master.php.net/note/delete/119762/non-english Del: in docs -- https://master.php.net/note/delete/119762/in+docs Del: other reasons-- https://master.php.net/note/delete/119762 Reject -- https://master.php.net/note/reject/119762 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#206323) next »