Title: Cannot use a scalar value as an array error in post.php
Last modified: August 19, 2016

---

# Cannot use a scalar value as an array error in post.php

 *  Resolved [audwan](https://wordpress.org/support/users/audwan/)
 * (@audwan)
 * [16 years, 11 months ago](https://wordpress.org/support/topic/cannot-use-a-scalar-value-as-an-array-error-in-postphp/)
 * I got these errors under Last Comments in the dashboard after I upgraded to 2.8.1:
 * > Warning: Cannot use a scalar value as an array in /home/foo/public_html/bar/
   > wp-includes/post.php on line 820
   > Warning: array_keys() [function.array-keys]: The first argument should be an
   > array in /home/foo/public_html/bar/wp-includes/post.php on line 821
   > Warning: Invalid argument supplied for foreach() in /home/foo/public_html/bar/
   > wp-includes/post.php on line 821
   > Warning: Cannot use a scalar value as an array in /home/foo/public_html/bar/
   > wp-includes/post.php on line 823
 * They seem to appear only on my own comments.
 * After changing a line of code in post.php the error messages disappeared. But
   as I’m not exactly a PHP guru (that’s an understatement), and this probably changes
   the behaviour of the blog when it comes to sanitation of inputs, I’d really like
   some help looking into it.
 * Is this a bug in WordPress, data corruption or something else? Any help would
   be appreciated.
 * Heres the original:
 *     ```
       function sanitize_post($post, $context = 'display') {
       	if ( is_object($post) ) {
       		if ( !isset($post->ID) )
       			$post->ID = 0;
       		foreach ( array_keys(get_object_vars($post)) as $field )
       			$post->$field = sanitize_post_field($field, $post->$field, $post->ID, $context);
       		$post->filter = $context;
       	} else {
       		if ( !isset($post['ID']) )
       			$post['ID'] = 0;
       		foreach ( array_keys($post) as $field )
       			$post[$field] = sanitize_post_field($field, $post[$field], $post['ID'], $context);
       		$post['filter'] = $context;
       	}
   
       	return $post;
       }
       ```
   
 * And this is what it looks like now:
 *     ```
       function sanitize_post($post, $context = 'display') {
       	if ( is_object($post) ) {
       		if ( !isset($post->ID) )
       			$post->ID = 0;
       		foreach ( array_keys(get_object_vars($post)) as $field )
       			$post->$field = sanitize_post_field($field, $post->$field, $post->ID, $context);
       		$post->filter = $context;
       	} else if ( is_array($post) ) {
       		if ( !isset($post['ID']) )
       			$post['ID'] = 0;
       		foreach ( array_keys($post) as $field )
       			$post[$field] = sanitize_post_field($field, $post[$field], $post['ID'], $context);
       		$post['filter'] = $context;
       	}
   
       	return $post;
       }
       ```
   

Viewing 10 replies - 1 through 10 (of 10 total)

 *  Thread Starter [audwan](https://wordpress.org/support/users/audwan/)
 * (@audwan)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/cannot-use-a-scalar-value-as-an-array-error-in-postphp/#post-1140736)
 * Same error appear in 2.8.2. Just in the Dashboard, and just on my own comments.
 *  [ibinbin](https://wordpress.org/support/users/ibinbin/)
 * (@ibinbin)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/cannot-use-a-scalar-value-as-an-array-error-in-postphp/#post-1140763)
 * Hello,
 * I’ve got the same proleme as you in the plugin page, no plugin are activated 
   and i cant see there name and description!!!
 * > Warning: Cannot use a scalar value as an array in /homez.22/jvglobet/www/wp-
   > admin/includes/plugin.php on line 123
   > Warning: Cannot use a scalar value as an array in /homez.22/jvglobet/www/wp-
   > admin/includes/plugin.php on line 128
   > Warning: Cannot use a scalar value as an array in /homez.22/jvglobet/www/wp-
   > admin/includes/plugin.php on line 136
 * Do you have any ideas about it, did you solved your probleme?
 * Regard,
 *  Thread Starter [audwan](https://wordpress.org/support/users/audwan/)
 * (@audwan)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/cannot-use-a-scalar-value-as-an-array-error-in-postphp/#post-1140765)
 * Sorry, I still have no fix other than the one in the first post.
 * Updated to 2.8.3, and the error is still there.
 *  [bishopj](https://wordpress.org/support/users/bishopj/)
 * (@bishopj)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/cannot-use-a-scalar-value-as-an-array-error-in-postphp/#post-1140766)
 * Which version of PHP are your running?
 * As it stands, if the $post value is neither an object nor an array you will simply
   pass it through. Prima-facie your code is partially better, except that there
   is an unhandled condition – that of a scalar value for $post that was clearly
   meant not to arise.
 * The error is therefore before that function – not in that function.
 * Which suggests one of three things:
    1. You have code mods else where that are
   wrong, or the upgrade did not replace all files in the original WP diretories
   2. The database upgrade did not take, so you have a wrong type for that field(
   unlikely). 3. In the words of rumsfield…there are things that we know, and things
   we know we don’t know, and things we don’t know that we don’t know…
 * I suggest looking at what calls that routine. My install of 2.8.3 does not exhibit
   this error (running on PHP 5). Handling of input fields from post/get actions
   were one of the big messy changes made between PHP 3 and 4, and then cleaned 
   up in early releases of 4.
 * I would first make sure that you have the version of php running that you think
   you have (although I would expect more extensive problems than this if you had
   the wrong version).
 * The standard advice with 2.8.3 seems to be to disable all plugins and then progressively
   re-enable them until the error resurfaces.
 *  [bishopj](https://wordpress.org/support/users/bishopj/)
 * (@bishopj)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/cannot-use-a-scalar-value-as-an-array-error-in-postphp/#post-1140767)
 * Actually, thinking about this – when the error occurs, what exactly is the value
   of $post? Does it have a value, or has it been passed 0 or NULL?
 * This would suggest that the routine is being called once too many times – particularly
   if the comments are otherwise appearing.
 *  Thread Starter [audwan](https://wordpress.org/support/users/audwan/)
 * (@audwan)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/cannot-use-a-scalar-value-as-an-array-error-in-postphp/#post-1140777)
 * Thanks for the answer, bishopj. I appreciate any help, or just a small push in
   the right direction.
 * The comments do indeed appear on the site, and the errors occur only on the comments
   from users that are logged in. I tried to add a new user (subscriber), and added
   a comment with that user, and it produced the same error in the Dashboard. That
   should narrow it down a bit, but I still got no clue how to fix it.
 * The blog runs on PHP 5.2.8 with MySQL 5.1.30. Other blogs running on the exact
   same platform don’t have the same issue, and some do.
 * I tried reinstalling all WordPress files and disabled all my plug-ins, but the
   problem still persists. I even checked the database to see if there was any issues
   with those specific comments, but didn’t find anything suspicious.
 * Is there any way I can output the value or type of $post? That would probably
   help.
 *  Thread Starter [audwan](https://wordpress.org/support/users/audwan/)
 * (@audwan)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/cannot-use-a-scalar-value-as-an-array-error-in-postphp/#post-1140784)
 * I’ve been doing some n00b-debugging, just to try getting to the bottom of this
   problem.
 * I replaced the _else_-line from the first post with:
    `} else if ( !is_null($
   post) ) {` and still get errors. That should suggest that $post being NULL is
   not the issue, right?
 * Then I tried:
    `} else if ( is_scalar($post['ID']) ) {` and the errors disappeard.
 * So $post[‘ID’] is not a scalar value when the error occurs, which means it is
   either array, object or resource (or perhaps not present)? (ref: [PHP:is_scalar](http://no.php.net/manual/en/function.is-scalar.php))
 * As a last resort I tried:
    `} else if ( !is_array($post['ID']) ) {` `} else if(!
   is_object($post['ID']) ) {` `} else if ( !is_resource($post['ID']) ) {` but I
   get errors on all of them, which is where my logic breaks.
 * Am I missing something here?
 *  [Chris Burbridge](https://wordpress.org/support/users/chrisbeee/)
 * (@chrisbeee)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/cannot-use-a-scalar-value-as-an-array-error-in-postphp/#post-1140805)
 * Please note that this error, “Warning: array_keys() [function.array-keys]: The
   first argument should be an array” can also be caused by the following:
 * * WP asks you for ftp information to install a theme or plugin, when you click
   Install.
    * The user you are referring to does not have sufficient permissions
   to do this
 * Update:
 * This fixed *part* of the problem, so now it uploads the files, but I am still
   getting another error, FYI.
 *  Thread Starter [audwan](https://wordpress.org/support/users/audwan/)
 * (@audwan)
 * [16 years, 5 months ago](https://wordpress.org/support/topic/cannot-use-a-scalar-value-as-an-array-error-in-postphp/#post-1140837)
 * The errors suddenly disappeared when I upgraded to WordPress 2.9.
 *  [jasonjinteractivenet](https://wordpress.org/support/users/jasonjinteractivenet/)
 * (@jasonjinteractivenet)
 * [16 years, 5 months ago](https://wordpress.org/support/topic/cannot-use-a-scalar-value-as-an-array-error-in-postphp/#post-1140839)
 * This isn’t an error. It’s a warning, and the developers probably don’t consider
   it a bug. Unless you’re in a testing environment, warnings should be supressed
   by your webserver. Printing stuff like that to the screen can be a serious security
   issue.
 * I supress these warnings in my own functions by preceding the offending statement
   with the ‘@’ symbol. Usually everything works fine, save for the weird message
   breaking the layout.

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘Cannot use a scalar value as an array error in post.php’ is closed to
new replies.

## Tags

 * [comment](https://wordpress.org/support/topic-tag/comment/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 10 replies
 * 5 participants
 * Last reply from: [jasonjinteractivenet](https://wordpress.org/support/users/jasonjinteractivenet/)
 * Last activity: [16 years, 5 months ago](https://wordpress.org/support/topic/cannot-use-a-scalar-value-as-an-array-error-in-postphp/#post-1140839)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
