0
I am studying a PHP OO book. There is an example of anonymous function, but is giving error:
# FUNÇÂO ANONIMA
$remove_acento = function($str) {
$a = array(
'à', 'á', 'â', 'ã', 'ä', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó',
'ô', 'õ', 'ö', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Ç', 'È', 'É',
'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ù', 'Ú', 'Û', 'Ü', 'Ý'
);
$b = array(
'a', 'a', 'a', 'a', 'a', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o',
'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'A', 'A', 'A', 'A', 'C', 'E', 'E',
'E', 'E', 'I', 'I', 'I', 'I', 'N', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y'
);
return str_replace($a, $b, $str);
}
print $remove_acento('José da Conceição');
When running, the following error occurs:
Parse error: syntax error, Unexpected 'print' (T_PRINT)
I see no direct error in this code. I use PHP 7.0.8.
I find it curious an OOP book teaching to use anonymous function :D I say that people use the term only for marketing...
– Maniero
Missing one
;
before theprint
:$remove_acento = function($str) { };
.– stderr
@Bigown Out of curiosity, you gave an answer and then closed the question as a typo. Is there any reason why this situation occurred?
– stderr
@stderr Because it is just a typo, you need an answer to be finalized, but it will not meet anyone else (formerly closed as Too specific). The standard is to do this, the reason for closure exists precisely for these cases.
– Maniero