Part of the EllisLab Network
   
 
PHP5 - private methods in controller
Posted: 02 February 2008 08:16 AM   [ Ignore ]  
Summer Student
Total Posts:  21
Joined  06-20-2006

If you try to call a private method from the url, CI will fail ungracefully showing the php error:

First argument is expected to be a valid callback, 'Your_controller::method' was given

Proposed fix in CodeIgniter.php line 217 is to replace

if ( ! method_exists($CI, $method))


with

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

Profile
 
 
Posted: 13 June 2008 08:50 PM   [ Ignore ]   [ # 1 ]  
Summer Student
Avatar
Total Posts:  26
Joined  04-21-2008

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

 Signature 

Officially Ignited cheese

Profile
 
 
Posted: 13 June 2008 08:54 PM   [ Ignore ]   [ # 2 ]  
Summer Student
Avatar
Total Posts:  26
Joined  04-21-2008

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.

 Signature 

Officially Ignited cheese

Profile
 
 
Posted: 14 June 2008 07:44 AM   [ Ignore ]   [ # 3 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1239
Joined  01-07-2008

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 .

 Signature 

Blog | Twitter | Coffee

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 62600 Total Logged-in Users: 24
Total Topics: 77073 Total Anonymous Users: 1
Total Replies: 416277 Total Guests: 145
Total Posts: 493350    
Members ( View Memberlist )
Newest Members:  eudj1nsehartEasyMLance SloanandrewjhscottShuvopatricovghazalravi_ghostblade_kaqfa