Skip to content

call_user_func() expects non-static method #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
marquesine opened this issue Feb 23, 2021 · 3 comments
Closed

call_user_func() expects non-static method #2

marquesine opened this issue Feb 23, 2021 · 3 comments

Comments

@marquesine
Copy link

Why is that? Is it part of the last PHP 7.4 updates?

Setting public static funcion won't cause any future problems?

Also, it is curious that the error is pointed, but the return of the function still appears below it.

Screenshot_2021-02-23 Screenshot

Isn't it better to instatiate SiteController, then call for it?

As follows:

$siteController = new SiteController();
$app->router->get('/contact', [$siteController, 'contact']);

@thecodeholic
Copy link
Owner

You should not set public static function because you won't be able to use $this keywork inside controller methods.

I think you don't have latest version of the code.
In latest version it automatically instantiates controller instance and uses that.
https://github.com/thecodeholic/tc-php-mvc-core/blob/master/Router.php#L55

@marquesine
Copy link
Author

marquesine commented Feb 23, 2021

Still curious on why it claims it has to be static method inside call_user_func().

I'll keep trying. So far, I have followed the tutorial by baby steps, and there it is working without the error.

@marquesine
Copy link
Author

Now I see the problem. @thecodeholic himself correct it around 1:11:15 of the freeCodeCamp.org youtube video.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants