PHP Warning: Illegal string offset 'user_login' in /home/.../wp-includes/user.php on line 83
PHP Warning: Illegal string offset 'user_password' in /home/.../wp-includes/user.php on line 83
Here the code:-
add_filter('authenticate', 'wp_authenticate_cookie', 30, 3);
$user = wp_authenticate($credentials['user_login'], $credentials['user_password']);
if ( is_wp_error($user) ) {
if ( $user->get_error_codes() == array('empty_username', 'empty_password') ) {
$user = new WP_Error('', '');
}
return $user;
}
Obviously $credentials is not that array. Show var_dump($credentials);
The error Illegal string offset 'whatever' in... generally means: you're trying to use a string as a full array.
That is actually possible since strings are able to be treated as arrays of single characters in PHP. So you're thinking the $var is an array with a key, but it's just a string with standard numeric keys
Try adding following lines before $ user
if(isset($_POST)){
$credentials = array(
'user_login' => isset($_POST['log']) ? $_POST['log'] : '',
'user_password' => isset($_POST['pwd']) ? $_POST['pwd'] :'',
);
}
Related
Hi I am getting the following message in my wordpress filter page for a holidays website:
Warning: Illegal string offset 'order' in /home/jefmaher/public_html/wp-content/themes/thevacationrental/functions.php on line 916
Warning: Illegal string offset 'order' in /home/jefmaher/public_html/wp-content/themes/thevacationrental/functions.php on line 917
This is the snippet of php
$i = 9999;
foreach( $options['customdatas'] as $key => $data ) {
if( empty( $data['order'] ) ) {
$options['customdatas'][$key]['order'] = $i;
$data['order'] = $i;
}
I am new to php and need some advice please
thanks
Jeff
"Illegal string offset" message indicates $data is not an array but rather a string, in, at least, one of the cases of foreach. One way to fix is to check if $data is, in fact an array.
if (is_array($data)) ;//
We're running PHP 5.3.10-1ubuntu3.15 with Suhosin-Patch, and I just ran across the weirdest thing. I keep getting an Array to string conversion error.
Here is some code with line numbers:
115 $report['report'][$key]['report'] = array();
116 watchdog('ranking_report_field', 'key is a: ' . gettype($key), array(), WATCHDOG_NOTICE);
117 $report['report'][$key]['report'] = array(
'#markup' => "<p>No information available.</p><p>For questions, <a href='mailto:$emailAddr'>email</a> your account executive ($emailAddr).</p>",
);
Here are Drupal's (sequential) logs for those line numbers:
Notice: Array to string conversion in foo() (line 115 of /var/www/...
key is a: string
Notice: Array to string conversion in foo() (line 117 of /var/www/...
So far as I can tell there's no array to string conversion that should be taking place. Someone help me out with a second pair of eyes, please - or is this some kind of bug that just hit PHP?
One of the array keys is mapped to a string not an array. Here is a program for how such an error could occur.
<?php
$key = 0;
$report = array();
$report['report'] = array();
$report['report'][$key] = 'report';
// Array to string conversion error
$report['report'][$key]['report'] = array();
// what I assume you are expecting is
$report['report'][$key] = array();
$report['report'][$key]['report'] = array(); // no more notices
NOTE: at his time the OP has not included info for how the array is created
I have a php code. I am just trying out to define and get array. The below is the code.
<?php
$query = 'summer';
$query['jink'] = array( 1,4,5,6 );
var_dump($query);
var_dump($query['jink']);
?>
var_dump returns:
string 'Aummer' (length=6)
string 'A' (length=6)
The output is not as expected. it should give something from (1,4,5,6)
I fixed your errors in order to show the issue:
$query = 'summer';
$query['jink'] = array( 1,4,5,6 );
$query is a string "summer" so ['jink'], not being a valid string offset is converted to 0 and it accesses the first character of "summer". Also, array( 1,4,5,6 ) is not a string it is Array and the "A" from Array is assigned to offset 0 of "summer" yielding "Aummer":
var_dump($query);
Now again you are getting string offset 0 which is "A" from "Aummer":
var_dump($query['jink']);
If you use error reporting:
error_reporting(E_ALL);
ini_set('display_errors', '1');
You will see:
PHP Warning: Illegal string offset 'jink' in file line
PHP Notice: Array to string conversion in file line
PHP Warning: Illegal string offset 'jink' in file line
What you maybe want is:
$query = ['summer'];
$query['jink'] = [1,4,5,6 ];
var_dump($query);
var_dump($query['jink']);
PHP Sandbox: http://sandbox.onlinephpfunctions.com/code/50f22fb5de571baf5978ab37e8cd645ec174125e.
Well the error is that you set the $query as a string then turn it into an array.You should simply edit $query = 'summer' to $query[] = 'summer' as this link shows.
list(,,,,,,,,,$user, $pass) = explode("\t", $line);
if(trim($user) == $_POST['username'] && trim($pass) == $_POST['password'] )
The message undefined offset 10 , The message undefined offset 9 . the 9 and the 10 is the $user and $pass. How do i fix the error? and does undefined offset means its not being declared or something? and theres alot of ,,,,,,,, is because theres value but i dont need it for this php
undefined offset in this context means that you are expecting more parameters in your call to list than are in the array on the right hand of the equation.
You are expecting an array with a length of 11 but explode("\t", $line) is returning an array of less than 11 values.
You either need to ensure you have the right amount of tab separated values in $line or pad the output of explode using array_pad.
Below is an example of using array_pad to make sure the array has a length of 11:
list(,,,,,,,,,$user, $pass) = array_pad(explode("\t", $line), 11, null);
If $line did not contain enough tab separated values then $user and $pass would take the value null.
I am using Codeigniter framework of PHP and trying to extract keywords from the page. The complete code for reference can be seen here. It is not ready-made though.
The issue is due to the array function in the following line:
$keywordCounts = array_count_values( $words );
The error message being displayed is as follows:
A PHP Error was encountered
Severity: Warning
Message: array_count_values() [function.array-count-values]: Can only count STRING and INTEGER values!
EDITED: The array $words for reference can be found here.
There are no special symbols or invalid characters to my knowledge in the $words array. Hyphens and periods are not read by the function or is there some other issue ?
you have null values in your array. you have to replace them before working with array_count_values like this:
$x = array('s'=>'ss', 'a',4 , 'sss' => null);
$ar = array_replace($x,array_fill_keys(array_keys($x, null),''));
$v = array_count_values($ar);
var_dump($v);
which will result:
array (size=4)
'ss' => int 1
'a' => int 1
4 => int 1
'' => int 1