What Does a \ (Backslash) Do in 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.

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 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

I don't understand why backslash is used in extends class in php code

It is used to let PHP know where the class exists. For example, \app\classes\TestClass will let it know that the class exists in app\classes directory/namespace. If you will not add the path, It will look for the class in the same Namespace!

PHP 5.3 Namespaces should i use every PHP function with backslash?

No matter the performance hit, no way should you do that. Ew, ew, ew. Any performance boost there may be is not worth your sanity.

What is the backslash in `new \SendGrid(...` within PHP?

\ (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.

[ Reference: What does a \ (backslash) do in PHP (5.3+)? ]

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.



Related Topics



Leave a reply



Submit