note 87176 modified in function.lcfirst by danbrown

From: Date: Mon, 24 Nov 2008 16:40:24 +0000
Subject: note 87176 modified in function.lcfirst by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-146877@lists.php.net to get a copy of this message
As of PHP release 6 direct reference modification is not permitted any more. Reference modification is the process of manipulating characters within a string by means of the instruction such as: $str[0] in the code line: $str[0] = strtolower($str[0]); For this reason I have recoded the lcfirst function (on function_exists('lcfirst') === false) as follows: <?php if ( false === function_exists('lcfirst') ): function lcfirst( $str ) { return (string)(strtolower(substr($str,0,1)).substr($str,1));} endif; ?> Remarks: Also notice that I have used the more modern scope delimeters (if:-endif;) and I have also removed the unnecessary intermediate result. That is, the manipulation is returned directly. --was-- As of PHP release 6 direct reference modification is not permitted any more. Reference modification is the process of manipulating characters within a string by means of the instruction such as: $str[0] in the code line: $str[0] = strtolower($str[0]); For this reason I have recoded the lcfirst function (on function_exists('lcfirst') === false) as follows: if ( false === function_exists('lcfirst') ): function lcfirst( $str ) { return (string)(strtolower(substr($str,0,1)).substr($str,1));} endif; Remarks: Also notice that I have used the more modern scope delimeters (if:-endif;) and I have also removed the unnecessary intermediate result. That is, the manipulation is returned directly. http://php.net/manual/en/function.lcfirst.php

« previous php.notes (#146877) next »