Consider the following two files. When you run test.php, what would the output look like?
Consider the following two files. When you run test.php, what would the output look like?
When running test.php, the included file MyString.php defines a namespaced version of the strlen function, which does not interfere with the global strlen function. Therefore, when test.php calls strlen("Hello world!"), it uses the global strlen function, producing a length of 12. In MyString.php, strlen("Hello world!") uses the namespaced strlen function which returns double the length of the string, resulting in 24. Hence, the output is 12, followed by 24.
E. PHP Fatal error: Cannot redeclare strlen()
Different Scopes