Welcome Guest, Not a member yet? Register   Sign In
PHP5 - private methods in controller
#1

[eluser]hepp[/eluser]
If you try to call a private method from the url, CI will fail ungracefully showing the php error:
Code:
First argument is expected to be a valid callback, 'Your_controller::method' was given

Proposed fix in CodeIgniter.php line 217 is to replace
Code:
if ( ! method_exists($CI, $method))
with
Code:
if ( ! method_exists($CI, $method) || ! is_callable(array($CI, $method)))

That way I don't have to prefix my methods with an underscore to keep them private Smile
#2

[eluser]Ergose[/eluser]
I'm finally getting back to my code and was wondering about this as I haven't tried it. Looks like you can help.

I've been using the underscores for now without question, but I would love to just use private instead as my IDE will catch it. So, is it safe to say you haven't run in to any problems with the is_callable or anything? In other words, might this impact things later or should this pretty well work 90% of the time without bugging up other parts of CI? If it's all gravy than you have just made me a happy coder. Smile
#3

[eluser]Ergose[/eluser]
Heh just noticed the date on this post. Well, regardless I'll keep an eye on this for a while if anyone has any insight. If I get around to testing it, I'll confirm.
#4

[eluser]Pascal Kriete[/eluser]
This was fixed in rev. 1002, so calling private or protected methods will 404 on the lastest version of CI. No need for changes Smile .




Theme © iAndrew 2016 - Forum software by © MyBB