Regarding the ':(colon symbol)' used when calling instance methods in PHP+Slim

Asked 1 years ago, Updated 1 years ago, 62 views

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 ,

$app->get('/', '\Tinitter\Controller\TimeLine:show');

and

TimeLine: Why is there only one colon in show ??

TimeLine I'm calling the class method show, but isn't it TimeLine::show??

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

php slim url-routing

2022-09-30 14:14

2 Answers

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.

$app->get('/', '\Tinitter\Controller\TimeLine:show');

→ If / 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.

Note: Slim Framework Document:RouteParameters


2022-09-30 14:14

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.