Php Error Invalid Argument Supplied For Foreach
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies invalid argument supplied for foreach() wordpress of this site About Us Learn more about Stack Overflow the company how to solve warning invalid argument supplied for foreach in php Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges
Invalid Argument Supplied For Foreach() Laravel
Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a
Invalid Argument Supplied For Foreach() Codeigniter
minute: Sign up PHP foreach invalid argument supplied up vote 0 down vote favorite I'm trying display error messages on a form but only one is displayed (the last one always). I tried using a foreach loop but I keep getting the invalid argument error. The following displays errors one by one. Code is inside a class... public $errorContainer = ''; // invalid argument supplied for foreach() array ------------------------------------------------------------ // ERROR MESSAGE PROCESSING // ------------------------------------------------------------ private function responseMessage($respBool, $respMessage) { $return['error'] = $respBool; $return['msg'] = $respMessage; if (isset($_POST['plAjax']) && $_POST['plAjax'] == true) { echo json_encode($return); } else { $this->errorContainer = $respMessage; } } The following always gives me the invalid for each argument error. private function responseMessage($respBool, $respMessage) { $return['error'] = $respBool; $return['msg'] = $respMessage; if (isset($_POST['plAjax']) && $_POST['plAjax'] == true) { echo json_encode($return); } else { foreach ($respMessage as $value) { $this->errorContainer = $value; } } } Thank you! php foreach share|improve this question edited Jun 2 '12 at 1:11 asked Jun 2 '12 at 1:03 user1002039 39231328 1 Is $respMessage an array? –nickb Jun 2 '12 at 1:08 How is this function called? –Niet the Dark Absol Jun 2 '12 at 1:08 This function is not called - the $errorContainer is. Sorry it should show private instead of public. I mean the function called only within the class. $this->responseMessage(true, $msg); –user1002039 Jun 2 '12 at 1:11 var_dump($respMessage) –tereško Jun 2 '12 at 1:11 try var_dump($respMessage); on the first line of
the PHP warning "Warning: Invalid argument supplied for foreach() in …". The warning is showing because
Invalid Argument Supplied For Foreach() In Opencart
I like to develop with error reporting turned on. $items = invalid argument supplied for foreach() laravel 5 $product->getFormats(); foreach ($items as $item) { // ... } This code results in a PHP Warning: invalid argument supplied for foreach() magento Warning: Invalid argument supplied for foreach() in ... There are a number of solutions for this ranging from turning error reporting off to surpressing the warnings. These have http://stackoverflow.com/questions/10859028/php-foreach-invalid-argument-supplied been detailed over on Stackoverflow. One fix is to check the variable's type first $items = $product->getFormats(); if (is_array($items)) { foreach ($items as $item) { // ... } } This is perfectly valid but I don't like it. This code base is already convoluted, with a mix HTML and PHP closely intertwined with each other*, https://www.euperia.com/development/fix-php-warning-invalid-argument-supplied-foreach/1230 so adding yet another closing brace 100's of lines down just adds to the complexity. The solution I prefer is to cast the variable to an array in the loop. This is a lot cleaner, requires less typing and only needs one edit on one line: $items = $product->getFormats(); foreach ((array) $items as $item) { // ... } } Unfortunately for me I need to do this quite a few times on this project, but the resulting code will be better for it. Unfortunately, budget constraints mean that refactoring our legacy projects just isn't feasible. There are absolutely no tests written and the majority of the projects don't use any kind of structured framework. « Can't find VirtualBox Guest Additions ISO?Quick Tip: PHPstorm Find and Replace Regex Dollar Sign ($) » AM Andrew McCombe Magento Certified Website Developer Staffordshire, UK Follow @euperia Twitter Google+ Github Latest Posts Magento Snippet: Use a Group By clause on a collection model Managing Homebrew Services I'm a Magento Certified D
Hacks » [Resolved] Invalid argument supplied for foreach() errors [Resolved] Invalid argument supplied for foreach() errors Peter Hardy-vanDoorn @petervandoorn 10 months, 3 weeks ago Since updating to the latest version I'm https://wordpress.org/support/topic/invalid-argument-supplied-for-foreach-errors/ seeing this error, but only on the backend: Warning: Invalid argument supplied for foreach() in /.../wp-content/plugins/advanced-access-manager/Application/Backend/Extension.php on line 87 and also on line 169 when viewing /admin.php?page=aam https://wordpress.org/plugins/advanced-access-manager/ Viewing 9 replies - 1 through 9 (of 9 total) Plugin Author Vasyltech @vasyl_m 10 months, 3 weeks ago Hi Peter, Thank you for your feedback. That is kind of a weird invalid argument warning, considering the fact that on the line 87 there is no foreach loop. Please try to install AAM Utilities extension and clear all settings. This might help you to avoid the second warning. Keep us updated. Regards, Vasyl Peter Hardy-vanDoorn @petervandoorn 10 months, 3 weeks ago I had thought to try the Utilities extension, but unfortunately the 2 errors completely invalid argument supplied break all AAM functionality, so the Download button doesn't work! I have also already tried deleting the plugin files and reinstalling via FTP, but I don't really want to try deleting it through WP as I don't really want to delete the extensive user role settings! Plugin Author Vasyltech @vasyl_m 10 months, 3 weeks ago Hi Peter, As a quick fix, you might try to go to database and remove the option aam-extension-list in your wp_options table. The permanent fix is coming with our new release AAM 3.0.4 in couple days. Thank you for your feedback and let me know if this works for you. Regards, Vasyl Studiobovenkamer @studiobovenkamer 9 months ago Hi Vasyl, Was this problem resolved? I'm running 3.0.9 and get the same warning: Warning: Invalid argument supplied for foreach() in ../wp-content/plugins/advanced-access-manager/Application/Backend/Manager.php on line 87. Warning: Invalid argument supplied for foreach() in ../wp-content/plugins/advanced-access-manager/Application/Backend/Extension.php on line 180 When visiting the AAM page in the admin I also get three alert pop-ups, all with the same warning: DataTables warning: table id=role-list - Invalid JSON response. For more information about this error,