Lodius2000 Posted April 5, 2012 Share Posted April 5, 2012 So I am extending the DateTime class and would like to completely disable the modify() function that is built in so i have this: <?php class NewDateTime extends DateTime { public function modify() { throw new Exception('modify() has been disabled.'); } } thats not the entire class description, just the pertinent part of course now any time I create a new object from NewDateTime I get this message at the top of the screen: Strict Standards: Declaration of NewDateTime::modify() should be compatible with that of DateTime::modify() in C:\xampp\htdocs\.....my file path here.....\NewDateTime.php on line 62 what gives? how do I get rid of this and still disable modify()? I'm betting its a setting that i have wonky but I am really rusty in php so dont know where to look in php.ini Quote Link to comment https://forums.phpfreaks.com/topic/260423-oop-datetime-extension-easy-question/ Share on other sites More sharing options...
Andy-H Posted April 5, 2012 Share Posted April 5, 2012 I assume that the class implements an interface that defines modify and it's params. try: public function modify($datetime = false) { throw new Exception('modify() has been disabled'); } ? Quote Link to comment https://forums.phpfreaks.com/topic/260423-oop-datetime-extension-easy-question/#findComment-1334821 Share on other sites More sharing options...
samshel Posted April 5, 2012 Share Posted April 5, 2012 this might help https://bugs.php.net/bug.php?id=46851 Quote Link to comment https://forums.phpfreaks.com/topic/260423-oop-datetime-extension-easy-question/#findComment-1334822 Share on other sites More sharing options...
Lodius2000 Posted April 6, 2012 Author Share Posted April 6, 2012 Andy-H That worked. just to make sure I understand how it worked (like i said, reeeeeeally rusty at my php): including the false value for $datetime means that modify() must accept some sort of argument, so if you put in an argument it returns false because it is supposed to throw an exception, and if you put no argument, the function returns false, which throws an exception right? Quote Link to comment https://forums.phpfreaks.com/topic/260423-oop-datetime-extension-easy-question/#findComment-1334841 Share on other sites More sharing options...
trq Posted April 6, 2012 Share Posted April 6, 2012 Far from correct. Currently the modify() method expects at least one argument. Your overloaded method didn't that is why you where getting the error. What Andy-H's code does is declares that your modify() also expects an argument, however he has also set a default value for this argument (of false) making it now optional. Quote Link to comment https://forums.phpfreaks.com/topic/260423-oop-datetime-extension-easy-question/#findComment-1334842 Share on other sites More sharing options...
Lodius2000 Posted April 6, 2012 Author Share Posted April 6, 2012 gotcha...makes perfect sense solved Quote Link to comment https://forums.phpfreaks.com/topic/260423-oop-datetime-extension-easy-question/#findComment-1334846 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.