Backslash in PHP -- what does it mean?
It's because they're using PHP namespaces. Namespaces are new as of PHP 5.3.
What does a \ (backslash) do in PHP (5.3+)?
\
(backslash) is the namespace separator in PHP 5.3.
A \
before the beginning of a function represents the Global Namespace.
Putting it there will ensure that the function called is from the global namespace, even if there is a function by the same name in the current namespace.
What does backslash do as prefix to a function name?
Introduced in PHP 5.3, \
is a namespace separator.
In your example, the outer strlen is MyFramework\MyString\strlen, the inner strlen is the global one.
Without any namespace definition, all class and function definitions are placed into the global space - as it was in PHP before namespaces were supported. Prefixing a name with \ will specify that the name is required from the global space even in the context of the namespace.
Reference: http://www.php.net/manual/en/language.namespaces.global.php
What does mean if (\false) (yes, with backslash) in PHP?
It means it's using the false defined in the global namespace..
After a bit of research it turns out the rest of this answer is nonesense... I could swear you were able to do this in PHP at one point in time.
I think this is get around the situation where
<?php
namespace whywouldyoudothis;
false = true;
?>
I have never ever seen anyone code for this but that's what springs to mind.
php string backslash followed by digit
The backslash within the string $str
is escaping the character immediately following it, you can prevent this behaviour by using single quotes, or; you can escape the backslash (wait for it...) by using a backslash.
echo $str = "IMAGES\2016\08\01\NM.jpg";
Result: IMAGES?68\NM.jpg
echo $str = "IMAGES\\2016\\08\\01\\NM.jpg";
Result: IMAGES\2016\08\01\NM.jpg
Aside: You could use str_replace
or preg_replace
to replace each single backslash with two backslashes.
Related Topics
Set Active State on Navigation Dynamically
PHP Function That Creates a Nested Ul Li
Generating Random Numbers from Skewed Normal Distribution
What Ocr Options Exist Beyond Tesseract
How So I Convert This Sha256 + Base64 from Swift to PHP
Connect to PHP Server Using Swift
Data from Two Tables with Same Column Names
PHP Session for Tracking Unique Page Views
Insert Query Check If Record Exists - If Not, Insert It
Forget Password Page, Creating a Generated Password to Email to the User
Woocommerce: Display Some Reviews Randomly on Home Page
Programmatically Creating New Order in Woocommerce
How to Use Break or Continue Within for Loop in Twig Template
How to Alias a Function in PHP
Email Validation Using Regular Expression in PHP
Create an Order Programmatically with Line Items in Woocommerce 3+