bigglescdh Posted December 28, 2009 Share Posted December 28, 2009 Hi, Apologies if this is a dumb question, I'm new to the forum. I'm using Zend Studio IDE, and trying to tidy up some code. Zend IDE gives warnings "Cannot re-declare function" with the following code (this example from wordpress) which I have seen used quite a lot. As far as I can see, because of the If/else the snippet will NOT re-declare ? - what is the correct way to code this snippet to avoid warnings? (is that possible??) or is it just code that Zend "doesn't like" if ( !function_exists('wp_nonce_field') ) { function akismet_nonce_field($action = -1) { return; } $akismet_nonce = -1; } else { function akismet_nonce_field($action = -1) { return wp_nonce_field($action); } $akismet_nonce = 'akismet-update-key'; } Many thanks Biggles Link to comment https://forums.phpfreaks.com/topic/186528-how-to-use-function_exists-without-warningserrors/ Share on other sites More sharing options...
Mchl Posted December 28, 2009 Share Posted December 28, 2009 This declares function akismet_nonce_field() so you should also check if it exists or not before. Link to comment https://forums.phpfreaks.com/topic/186528-how-to-use-function_exists-without-warningserrors/#findComment-985091 Share on other sites More sharing options...
bigglescdh Posted December 28, 2009 Author Share Posted December 28, 2009 This declares function akismet_nonce_field() so you should also check if it exists or not before. Indeed it does, but the actual warning appears only on line 5 and says Cannot re-declare function 'askimet-nonce-field' So Zend seems to ignore the If/else construct Link to comment https://forums.phpfreaks.com/topic/186528-how-to-use-function_exists-without-warningserrors/#findComment-985098 Share on other sites More sharing options...
Mchl Posted December 28, 2009 Share Posted December 28, 2009 Try like this: if ( !function_exists('akismet_nonce_field') ) { if ( !function_exists('wp_nonce_field') ) { function akismet_nonce_field($action = -1) { return; } $akismet_nonce = -1; } else { function akismet_nonce_field($action = -1) { return wp_nonce_field($action); } $akismet_nonce = 'akismet-update-key'; } } [/code] Link to comment https://forums.phpfreaks.com/topic/186528-how-to-use-function_exists-without-warningserrors/#findComment-985100 Share on other sites More sharing options...
bigglescdh Posted December 28, 2009 Author Share Posted December 28, 2009 Mchl, Many thanks, that does work. It would appear that Zend identifies the wrong part of the line to flag the warning! (i.e. the first function, not the second) Many thanks biggles Link to comment https://forums.phpfreaks.com/topic/186528-how-to-use-function_exists-without-warningserrors/#findComment-985123 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.