What does a colon mean in PHP?
I recently started learning PHP.
There was a sample of the Slim framework in the book, so I am copying the sutra while understanding the meaning of it.
Therefore, I have some questions.
↓Slim Sample Application With the Tinter code ,
TimeLine: Why is there only one colon in show ??
TimeLine I'm calling the class method
show, but isn't it
In the case of instance method, I think it is called by the Arrow operator, but in the case of class method, do you mean that
: is called between
: instead of
This is Slim's own expression and has nothing to do with PHP.
This is the routing (sorting) part of the process by URL.Determines the URL pattern and specifies what to do with the matching pattern.
/ has HTTP access, it is assumed that
TimeLine is instantiated and the
show method is used as the method to handle HTTP.
It's PHP-like to instantiate it carefully for each access.
The method of specifying the instance method in
: seems to have been added to Slim 2.4.0 and does not appear in document, so it is only natural that you should be questioned.The release notes also mention that the ,
:, appears to be a static method call.
'\Tinitter\Controller\TimeLine:show' part of this code is simply a "string" for the PHP language structure.The class and method correspond to it, so it looks like PHP's language structure, which is confusing, but PHP doesn't interpret anything from this string.
When you invoke
$app->get() in the Slim framework code as described above, the
setCallable() method of the
Route class in the framework is called.
If you look at this code, you can see that if the specified one is a string and there is a colon, you divide it into class names and methods, and then instantiate the class.
© 2023 OneMinuteCode. All rights reserved.