There is a recommendation on https://phptherightway.com/pages/The-Basics.html using backslash for global functions. Take a look at this code:
<?php
namespace myspace;
class MyClass
{
public $myvar = 'test';
public function myfunction()
{
$withoutBackslash = json_encode($this->myvar);
$withBackslash = \json_encode($this->myvar);
return [$withBackslash, $withoutBackslash];
}
}
How is better with or without backslash? I never used them before should I change my code in either direction (removing or adding)?
No, since you do not have global functions, only classes, then there is no point in separate them. They are using \fopen
because they have phptherightway\fopen
In that case writing just fopen
will refer to phptherightway\fopen
instead of global fopen
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With