Hopefully, you guys can help me here. What's going on with these issues in my WordPress install, see the errors and referenced code block.
Errors:
Warning: Illegal string offset 'domain' in /home/customer/www/xxxxxxxx.xxx/public_html/wp-includes/l10n.php on line 583
Warning: Illegal string offset 'context' in /home/customer/www/xxxxxxxx.xxx/public_html/wp-includes/l10n.php on line 587
Warning: Illegal string offset 'singular' in /home/customer/www/xxxxxxxx.xxx/public_html/wp-includes/l10n.php on line 588
Warning: Illegal string offset 'plural' in /home/customer/www/xxxxxxxx.xxx/public_html/wp-includes/l10n.php on line 588
Warning: Illegal string offset 'context' in /home/customer/www/xxxxxxxx.xxx/public_html/wp-includes/l10n.php on line 588
Warning: Illegal string offset 'domain' in /home/customer/www/xxxxxxxx.xxx/public_html/wp-includes/l10n.php on line 583
Warning: Illegal string offset 'context' in /home/customer/www/xxxxxxxx.xxx/public_html/wp-includes/l10n.php on line 587
Warning: Illegal string offset 'singular' in /home/customer/www/xxxxxxxx.xxx/public_html/wp-includes/l10n.php on line 588
Warning: Illegal string offset 'plural' in /home/customer/www/xxxxxxxx.xxx/public_html/wp-includes/l10n.php on line 588
Warning: Illegal string offset 'context' in /home/customer/www/xxxxxxxx.xxx/public_html/wp-includes/l10n.php on line 588
Code:
function translate_nooped_plural( $nooped_plural, $count, $domain = 'default' ) {
if ( $nooped_plural['domain'] ) {
$domain = $nooped_plural['domain'];
}
if ( $nooped_plural['context'] ) {
return _nx( $nooped_plural['singular'], $nooped_plural['plural'], $count, $nooped_plural['context'], $domain );
} else {
return _n( $nooped_plural['singular'], $nooped_plural['plural'], $count, $domain );
}
}
Warning: Illegal string offset 'something' message means that you're trying to access the value of $someVar['something'] but it doesn't exist.
To avoid it, you should always use isset($someVar['something']) to check if the index exists (or not) in the given variable.
Related
i created custom plugin few years ago and now i have in my admin plugin page error Warning: Undefined array key "home_team" ....
Here is my code:
function DBP_insert_data()
{
global $wpdb;
$table_name = $wpdb->prefix . 'funstar_league';
$DBP_home = $_POST['home_team'];
$DBP_guest = $_POST['guest_team'];
$DBP_home_team_url_logo = $_POST['home_team_url_logo'];
$DBP_guest_team_url_logo = $_POST['guest_team_url_logo'];
$DBP_home_team_url_logo = $_POST['home_team_url_logo'];
$DBP_url = $_POST['url'];
$DBP_place = $_POST['place'];
$DBP_time = $_POST['game_time'];
$DBP_date = $_POST['game_date'];
if (isset($_POST['save'])) {
$wpdb->insert(
$table_name,
array(
'home_team' => $DBP_home,
'guest_team' => $DBP_guest,
'home_team_url_logo' => $DBP_home_team_url_logo,
'guest_team_url_logo' => $DBP_guest_team_url_logo,
'url' => $DBP_url,
'place' => $DBP_place,
'game_time' => $DBP_time,
'game_date' => $DBP_date,
),
array(
'%s', // Use string format
'%s',
'%s',
'%s',
'%s',
)
);
}
}
Here is error post:
Warning: Undefined array key "home_team" in /Users/tomasvalach/www/fun_2/wp-content/plugins/extraliga/extraliga_insert_file.php on line 133
Warning: Undefined array key "guest_team" in /Users/tomasvalach/www/fun_2/wp-content/plugins/extraliga/extraliga_insert_file.php on line 134
Warning: Undefined array key "home_team_url_logo" in /Users/tomasvalach/www/fun_2/wp-content/plugins/extraliga/extraliga_insert_file.php on line 135
Warning: Undefined array key "guest_team_url_logo" in /Users/tomasvalach/www/fun_2/wp-content/plugins/extraliga/extraliga_insert_file.php on line 136
Warning: Undefined array key "home_team_url_logo" in /Users/tomasvalach/www/fun_2/wp-content/plugins/extraliga/extraliga_insert_file.php on line 137
Warning: Undefined array key "url" in /Users/tomasvalach/www/fun_2/wp-content/plugins/extraliga/extraliga_insert_file.php on line 138
Warning: Undefined array key "place" in /Users/tomasvalach/www/fun_2/wp-content/plugins/extraliga/extraliga_insert_file.php on line 139
Warning: Undefined array key "game_time" in /Users/tomasvalach/www/fun_2/wp-content/plugins/extraliga/extraliga_insert_file.php on line 140
Warning: Undefined array key "game_date" in /Users/tomasvalach/www/fun_2/wp-content/plugins/extraliga/extraliga_insert_file.php on line 141
Writing:
define ("MYARR", array(
'TITLE' => "MY TITLE",
) );
And giving:
print_r(MYARR);
No error is returned. It is all ok! I display:
Array
(
[TITLE] => MY TITLE
)
But if i write:
define ("MYARR['TITLE']", "MY TITLE");
I don't get a error, but giving:
print_r(MYARR);
I get:
Warning: Use of undefined constant MYARR - assumed 'MYARR'
And giving:
echo MYARR['TITLE'];
I get this two warning:
1) Warning: Use of undefined constant MYARR
2) Warning: Illegal string offset 'TITLE'
About first warning, it not is correct, becouse as is possible to see above it is declared!
I think which is a bug of PHP. From a side is allowed declare constant of array but of other side not allowed. What is your opinion?
Warning [2] Illegal string offset 'title' - Line: 66
if(!isset($params['title'])) {
$params['title'] = "Hidden Content";
}
and Warning [2] Illegal string offset 'title' - Line: 3
eval("\$return = \"".$templates->get("lock_wrapper")."\";");
Please help!
I am tried to add the same string to every array value.
I tried to use array_walk() like I read it on this answer.
But I get: Notice: Array to string conversion
I have also tried to use array_map(), but I get same error notice.
working code
if ($voice->getValue() === Voice::Passive) {
array_walk($aller_form, function(&$value, $key) { $value .= ' être'; });
$aller_form = [
Mood::Indicatif => [
Tense::Futur_compose => [
Person::FirstPersonSingular => 'vais être',
Person::SecondPersonSingular => 'vas être',
Person::ThirdPersonSingular => 'va être',
Person::FirstPersonPlural => 'allons être',
Person::SecondPersonPlural => 'allez être',
Person::ThirdPersonPlural => 'vont être'
]
]
];
}
return $aller_form[$mood->getValue()][$tense->getValue()][$person->getValue()];
not working code
if ($voice->getValue() === Voice::Passive) {
array_walk($aller_form, function(&$value, $key) { $value .= ' être'; });
}
return $aller_form[$mood->getValue()][$tense->getValue()][$person->getValue()];
EDIT:
The complete error log:
Notice: Array to string conversion in on line 2
Warning: Illegal string offset 'futur_compose' on line 4
Warning: Illegal string offset 'firstPersonSingular' on line 4
(I see 6 times this three error lines for every Person once)
This question already has answers here:
Illegal String Offset within PDO For Each loop
(2 answers)
Closed 8 years ago.
After completing a SELECT query on a MySQL database and applying the fetchAssoc() method to the result, I am receiving warnings when attempting to access the results in a foreach loop. Here is the code:
$query=$subquery->execute()->fetchAssoc();
foreach($query as $result) {
if ($result['active'] == 'Y'){ // (this is line 703)
$page_id = $result['page_id']; // (this is line 704)
if (!$package_pages[$page_id] || $package_pages[$page_id] != $page_id) { // line 705
$pages[] = $page_id;
}
}
I inserted var_dump($query) to inspect the results of the query. Here is an example of the output:
array (size=3)
'page_name' => string 'Apts & Rentals' (length=14)
'page_id' => string '49' (length=2)
'active' => string 'Y' (length=1)
array (size=3)
'page_name' => string 'Homepage' (length=8)
'page_id' => string '1' (length=1)
'active' => string 'Y' (length=1)
There are 25 arrays output from var_dump($query)
And here is a sample of the warnings:
Warning: Illegal string offset 'active' in ads_load() (line 703 of ...
Warning: Illegal string offset 'page_id' in ads_load() (line 704 of ...
Notice: Undefined index: Y in ads_load() (line 705 of ...
Why are the offsets 'active', and 'page_id' being flagged as illegal?
Where is the "Notice: Undefined index: Y" coming from since it is not being used as an index on line 705?
I don't believe this is a duplicate of Illegal String Offset within PDO For Each loop. The issue was resolved when I realized the code given above was placed within another loop which gave the impression I was dealing with an array of arrays rather than a single array each time.
You're accessing them incorrectly - you've got an associative array and you're trying to loop through it as if it were an array of associative arrays. This is your dumped data structure:
$query = array(
'page_name' => 'Homepage',
'page_id' => '1',
'active' => 'Y' );
You can get the results directly from $query, i.e.:
$query=$subquery->execute()->fetchAssoc();
if ($query['active'] == 'Y')
$page_id = $query['page_id'];
// ... the rest of your code ...
}
You could iterate through the keys and values of $query, but since you are interested in particular values from the $query array, there isn't much point.