What do two colons mean in PHP?
That's (generally) for accessing a static method or property in a class. It's called the scope resolution operator, or Paamayim Nekudotayim (which leads to some amazingly confusing error messages!). See http://www.php.net/manual/en/language.oop5.paamayim-nekudotayim.php.
What does double colon in laravel means
::
Scope Resolution Operator
::
is called as scope resolution operator
(AKA Paamayim Nekudotayim). This operator is used to refer the scope of some block or program context like classes, objects, namespace and etc. For this reference an identifier is used with this operator to access or reproduce the code inside that scope.
Reference
Auth::guard($guard)->guest()
: In this line you are using the guard() method of static class Auth
. To use the function of a static class we use ::
Scope Resolution Operator.
Difference between double colon and arrow operators in PHP?
::
is for static elements while ->
is for instance elements.
For example:
class Example {
public static function hello(){
echo 'hello';
}
public function world(){
echo 'world';
}
}
// Static method, can be called from the class name
Example::hello();
// Instance method, can only be called from an instance of the class
$obj = new Example();
$obj->world();
More about the static concept
What is Ruby's double-colon `::`?
::
is basically a namespace resolution operator. It allows you to access items in modules, or class-level items in classes. For example, say you had this setup:
module SomeModule
module InnerModule
class MyClass
CONSTANT = 4
end
end
end
You could access CONSTANT
from outside the module as SomeModule::InnerModule::MyClass::CONSTANT
.
It doesn't affect instance methods defined on a class, since you access those with a different syntax (the dot .
).
Relevant note: If you want to go back to the top-level namespace, do this: ::SomeModule – Benjamin Oakes
What does : mean in PHP?
It's called an Alternative Syntax For Control Structures. You should have an endwhile;
somewhere after that. Basically, it allows you to omit braces {}
from a while to make it look "prettier"...
As far as your edit, it's called the Ternary Operator (it's the third section). Basically it's an assignment shorthand.
$foo = $first ? $second : $third;
is the same as saying (Just shorter):
if ($first) {
$foo = $second;
} else {
$foo = $third;
}
PHP: How to create function which will be accessible with :: (double colon, scope resolution) in another classes
The double colon allows access to static function and constants in a class.
Change your class method to:
static function runTests() {
...
and then call it like this
DoSomethin::runTests();
String :: and __ the double colon and double underscore in PHP
:: = Scope resolution operator: http://www.php.net/manual/en/language.oop5.paamayim-nekudotayim.php
The __-prefix is a convention surrounded by built-in magic: http://www.php.net/manual/en/userlandnaming.rules.php, never start a function or variable with this if you can avoid it.
The first is a token, the second a convention.
If you really want to know most tokens, see: http://www.php.net/manual/en/tokens.php
If you want to know more about naming conventions, see: http://www.php.net/manual/en/userlandnaming.php
When starting out with PHP it would hurt to read Zend coding conventions, although it's not a must and not the only way by a long shot: http://framework.zend.com/manual/en/coding-standard.html
Related Topics
PHP Call_User_Func VS. Just Calling Function
Extract Url's from a String Using PHP
How to Properly Display Chinese Characters in PHP
How to Trigger Xdebug Profiler for a Command Line PHP Script
PHP Regex to Remove Http:// from String
Using Xampp, How to Swap Out PHP 5.3 for PHP 5.2
Array Merge on Multidimensional Array
How Is Output(Echo) Array Without Use of JSON_Encode(Codeigniter)
Select MySQL Based Only on Month and Year
What Are the Benefits of Oo Programming? Will It Help Me Write Better Code
Check If String Is Just White Space
Fatal Error: Cannot Use Object of Type Stdclass as Array In