CodeIgniter Forums
Private methods are preventing me extending the CI_Email class - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Private methods are preventing me extending the CI_Email class (/showthread.php?tid=42872)



Private methods are preventing me extending the CI_Email class - El Forum - 06-22-2011

[eluser]triplethree[/eluser]
Hi guys

I'm trying to extend the CI email library but I'm struggling as a number of the methods that I want to replace or call are private. Is there a way around this, or should I change the methods in the CI class to be protected / public?

Thanks in advanced.


Private methods are preventing me extending the CI_Email class - El Forum - 06-22-2011

[eluser]toopay[/eluser]
There are several ways, but inefficient (like duplicate or play with constructor, in the original class). So if you really have to change those private function, changes several methods visibility obviously your best option.


Private methods are preventing me extending the CI_Email class - El Forum - 06-22-2011

[eluser]Aken[/eluser]
There's nothing wrong with editing the system files if you want/need. Just need to remember that you made those changes if/when you upgrade.

I personally would copy the entire Email class into your own MY_Email.php, and then change the methods and add whatever you need. That way if you upgrade the system folder, your changes won't be overwritten. Then you just need to check the change logs to see if there have been any changes to the Email class so you can match/update.

This issue has been brought up on the Reactor core thing on BitBucket, so it will be addressed eventually. Who knows when, though.


Private methods are preventing me extending the CI_Email class - El Forum - 06-22-2011

[eluser]WanWizard[/eluser]
In general, this approach sucks, and breaks lots of third-party libraries that depend on accessing core libraries to integrate themselfs with CI.

For those libraries you can't follow the usual approach of creating MY_Loader, MY_Model and the other MY's, as you'll end up with several third party libraries all needing to extend these core libraries. It's a merge nightmare waiting to happen, and it seriously tempered my enthusiasm for CI.


Private methods are preventing me extending the CI_Email class - El Forum - 06-22-2011

[eluser]wiredesignz[/eluser]
None of CodeIgniter library methods should be private. If anything they should be protected methods so they can be extended freely but are unavailable outside of the class.

Another example of a problem introduced by the Reactor development team. They've seen @access marked private in the original class and given it no further thought.

@triplethree, Raise a bug report on the Reactor repository, they might get around to fixing it.


Private methods are preventing me extending the CI_Email class - El Forum - 06-23-2011

[eluser]triplethree[/eluser]
Thanks for the replies guys! Personally I would have thought these methods should be protected or public as mentioned above. I'll log a bug and see what happens Smile I like the idea of duplicating the whole library to ease core upgrades later on.