Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Dummy file logger
- *
- * @param array | string $message
- */
- function writeToLogFile($message = null): void
- {
- echo print_r($message, TRUE);
- }
- /**
- * Our example method to depreacte
- *
- * @param string $name
- * @deprecated 02 Feb 2019
- */
- function capitaliseNames($name)
- {
- trigger_error(__METHOD__ . '() is deprecated, use capitaliseWords() instead', E_USER_DEPRECATED);
- ## and / or we'll write to our log file
- writeToLogFile(['deprecated' => 'Deprecated method or function called ' . __METHOD__ . '()']);
- ## If we are confident our replacement method or function
- ## is like for like, we can call it here, i.e.,
- ## return capitaliseWords($name);
- ##
- ## If we are still developing the replacement method or function
- ## to what we're deprecating then allow the rest of this to run
- ## so we don't get unexpected results
- $name = trim($name);
- $name = explode(' ', $name);
- $returnName = '';
- foreach($name as $namePart){
- $returnName .= ucfirst($namePart) . ' ';
- }
- return trim($returnName);
- }
- /**
- * Our example new method, returns
- * capitalisation after each space
- * and removes any whitespaces
- *
- * @param string $name
- * @return string
- */
- function capitaliseWords(string $words = null): string
- {
- return ucwords(trim($words));
- }
- $name = 'john ian smith';
- echo capitaliseNames($name);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement