william@960design.com Posted August 19, 2011 Share Posted August 19, 2011 Howdy, this one is killing me! Hope some of the genius here will rub off on me. Very simple example of what is happening: Base.php class Base_Model //class autoloaded { protected function scrub($value) { return trim(htmlspecialchars($value, ENT_QUOTES, "UTF-8")); } } Foo.php class Foo_Model extends Base_Model { if($_POST) { $_POST = array_map('parent::scrub', $_POST); } } This works perfectly on the workstation (MAMP) server, but generates a warning ( Warning: array_map() [function.array-map]: The first argument, 'parent::scrub', should be either NULL or a valid callback in... ) when uploaded to the production server. Both are running the exact same version of php. Any ideas would be appreciated on getting rid of the error, besides turning off warnings ( haha ). William Quote Link to comment Share on other sites More sharing options...
Alex Posted August 19, 2011 Share Posted August 19, 2011 Try this: $_POST = array_map(array($this, 'parent::scrub'), $_POST); Quote Link to comment Share on other sites More sharing options...
WebStyles Posted August 19, 2011 Share Posted August 19, 2011 if($_POST) will probably always return true. If you're wanting to detect if something was posted, try something like: if($_SERVER['REQUEST_METHOD']=="POST") Quote Link to comment Share on other sites More sharing options...
xyph Posted August 19, 2011 Share Posted August 19, 2011 http://www.php.net/manual/en/language.pseudo-types.php#language.types.callback I doubt they're the exact same version // Type 4: Static class method call (As of PHP 5.2.3) call_user_func('MyClass::myCallbackMethod'); and // Type 5: Relative static class method call (As of PHP 5.3.0) class A { public static function who() { echo "A\n"; } } class B extends A { public static function who() { echo "B\n"; } } call_user_func(array('B', 'parent::who')); // A Also levi at alliancesoftware dot com dot au 08-Feb-2007 10:44 Parent methods for callbacks should be called 'parent::method', so if you wish to call a non-static parent method via a callback, you should use a callback of <? // always works $callback = array($this, 'parent::method') // works but gives an error in PHP5 with E_STRICT if the parent method is not static $callback array('parent', 'method'); ?> Quote Link to comment Share on other sites More sharing options...
william@960design.com Posted August 19, 2011 Author Share Posted August 19, 2011 @Alex: pure genius ( i think i got a little on me, thanks ) I had to mod it slightly: $_POST = array_map(array($this, 'Base_Model::scrub'), $_POST); Could that be because of the way the mvc framework autoloads/includes class files? I dislike using the Base_Model and would rather use parent. @xyph: excellent information, I'll try those ideas @webstyles: please correct my thinking here, $_POST is only created after the form has been submitted, the $_POST gets pushed to whatever file.php you wish, in this case it is getting pushed to the same file. The second time ( and third, forth, fifth, ect ) the file loads the if($_POST) would be true, but not the first time. Quote Link to comment Share on other sites More sharing options...
xyph Posted August 19, 2011 Share Posted August 19, 2011 $_POST will always exist. It's a superglobal array. <?php if( is_array($_POST) ) echo 'This will output always'; if( !empty($_POST) ) echo 'This will output when a form is submit through POST'; ?> Quote Link to comment Share on other sites More sharing options...
william@960design.com Posted August 20, 2011 Author Share Posted August 20, 2011 @xyph: try this one mate <h1>Post Test</h1> <form name=posttest action='' onsubmit=submit.disabled=true; method=post> <ul> <li> <label class='' for=field>Field Label </label> <input type=text name=field value='' title='' maxlength=30 > </li> </ul> <input type=submit name=submit onclick=this.value='Submitting…' value='Test' > </form> <?php if($_POST) { echo "xyph was right"; } else { echo "xyph was wrong"; } ?> Not really sure why you threw the is_array($_POST) in the mix as it's only testing if $_POST is an array, which isn't the same thing I posted above. The second one !empty($_POST) is almost exactly the same, except I saved a couple nano seconds by removing the negative test from the empty() method call and just tested for $_POST only. Thanks for the explanation though. Try my code above and see what it does for you. Thanks guys, I'm marking this as fixed. William Quote Link to comment 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.