foreach() argument must be of type array|object
foreach() argument must be of type array|object means a loop receives something other than a suitable collection.
Which PHP version does your site report?
We read only what your site already sends in public: the headers and the top of the homepage. No scan, no login.
More about this
A loop might process the items displayed in an overview.
The message also names the actual supplied type, such as null or bool.
Keep that part because it helps distinguish missing data from a result carrying a different meaning.
Before you start
Save the complete error line and its timestamp in a private note. Record the action that failed, the current PHP versionA PHP version is a numbered edition of PHP, like 8.3. Each edition is looked after for a limited time, then gets security fixes only, then nothing. and any components updated at the same time. Share only information needed for the investigation.
Public support forums are not suitable places for customer details, access credentials or complete server paths.
Back up both files and the database before making changes. Check that the backupA backup is a separate copy of your website's files and database, so you can bring the site back after a mistake, a hack or a failed update. is usable. Work on a restricted test copy with the same PHP version and relevant settings.
Disable real payments and outgoing customer emails there. Agree who will make the change and who will check the result. These steps are an investigation guide, not a diagnosis of your particular website.
What changed? The PHPPHP is a programming language that builds your web pages on the computer that hosts your site, just before they reach the visitor. WordPress runs on it. manual describes foreach for arrays and objects. Other types and uninitialized variables are not valid input for this construct.
The underlying problem also existed before PHP 8, although message wording can differ. An empty collection differs from the absence of a collection. Start by checking what enters the loop rather than editing the contents of individual items that may never have been supplied.
Choosing the correct repair
Ask the maintainer to identify the function supplying the collection. No results might legitimately mean an empty array, while failed processing needs a separate response. Record that contract.
Blindly converting a boolean to an array does not make its meaning correct. For an import, 'no rows available' differs from 'file not processed'. Presenting both as an unexplained success could mislead the person performing the task.
Five steps to a repair
- Record the complete message, including the supplied type. Identify the overview, form or background process that uses the loop and the test input offered to it.
- Find the code supplying the collection. Inspect its result before the loop. Compare the type during a normal run with the type observed during the failure.
- Agree how an empty collection differs from failed processing. Repair the supplying code or add focused handling for the outcomes the application is intended to accept.
- Test several items, zero items and a deliberately failed input operation. Check the user-facing explanation and whether any information was actually processed in each separate case.
- Repeat the original route and compare input with output. Count processed test items and ensure no empty or invented row was added merely to remove the warning.
A practical check
An import sample containing three identifiable test rows makes one useful acceptance exercise. All three should appear in the intended overview. A valid empty file should explain that nothing needed processing.
A file that could not be processed needs a different message and must not imply a successful import. Ask the administrator to check these distinctions. This is a test design, not a claim that your pluginA WordPress plugin is an add-on you install in WordPress to give your site extra features, such as contact forms, SEO tools or a webshop. performs imports.
It makes the supplied input and actual work of the loop observable.
Getting help and checking the repair
Use the help form below if you cannot access the logs or do not know who maintains the affected code. Describe one failed action and the expected result. Ask for a proposal that separates the cause, the change and the acceptance check.
Do not include passwords with your request.
After the repair, repeat the original action on the test copy. Also check a normal visitor journey, an empty result and invalid input where relevant. Review fresh log entries at the new test time.
Keep versions and outcomes in your maintenance notes. Let the responsible administrator decide when the tested change can be applied to the live website.
Choosing the next step
Use the links below this article to choose the next step. The PHP update page helps you discuss maintenance with the administrator. The Exposure Check is a separate public check; do not treat its result as evidence that this programming error is repaired.
Use the status page for current security information. Keep the repair of the visitor action and the assessment of the server as separate checks in your notes. When requesting help, include the error text, the failed action and the expected result, but no passwords.
Ask for one responsible person to oversee both the change and its acceptance.