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!
Related
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?
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.
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)
Not sure if data issue or program issue, sometimes below program
show error message :
PHP Warning : "illegal string offset '#id' in test.php"
PHP Warning : "illegal string offset 'Order' in test.php"...
....
$ret1=curlDest($transaction_url);
$retval = $ret1["Response"]["TransactionList"]["#TotalCount"];
foreach ($ret1["Response"]["TransactionList"]["Transaction"] as $v)
{
$transaction_id = $v["#Id"];
$order_id = array();
$orderid_query_string = '';
foreach ($v["Order"] as $order)
{...
}
the data of #ret1 is below
Array
<
[#Id] => 120852760
[Order] = > Array
<
[#Id] => YM152222
>
>
The error said
illegal string offset '#id'
You should use a capitalized #Id instead.
$imageTypes = array("image/gif", "image/jpeg", "image/png","image/jpg");
$uploadData = array_shift($check);
print_r($uploadData)
Array
(
[name] => Chrysanthemum.jpg
[type] => image/jpeg
[tmp_name] => C:\xampp\tmp\phpAADE.tmp
[error] => 0
[size] => 879394
)
if(!in_array($uploadData['type'],$imageTypes)){
return false;
}
But i m getting error Uninitialized string offset: 0 in this below line
if(!in_array($uploadData['type'],$imageTypes)){
On your piece of code $check is undefined.
$imageTypes = array("image/gif", "image/jpeg", "image/png","image/jpg");
$uploadData = array_shift($check);
if(!in_array($uploadData['type'],$imageTypes)){
return false;
}
Maybe you have to fix by:
$imageTypes = array("image/gif", "image/jpeg", "image/png","image/jpg");
$uploadData = array_shift($imageTypes);
if(!in_array($uploadData['type'],$imageTypes)){
return false;
}
I think I understand what might be happening here. The value you array_shift() from the $check array might be an empty string. Consider the following example:
$imageTypes = array("image/gif", "image/jpeg", "image/png","image/jpg");
$check = array(
'' // empty string
);
$uploadData = array_shift($check);
var_dump(in_array($uploadData['type'], $imageTypes));
This raises the following warnings/notices:
PHP Warning: Illegal string offset 'type' in /Users/darragh/Sites/so.php on line 26
PHP Stack trace:
PHP 1. {main}() /Users/darragh/Sites/so.php:0
PHP Notice: Uninitialized string offset: 0 in /Users/darragh/Sites/so.php on line 26
PHP Stack trace:
PHP 1. {main}() /Users/darragh/Sites/so.php:0
Warning: Illegal string offset 'type' in /Users/darragh/Sites/so.php on line 26
Call Stack:
0.0002 227040 1. {main}() /Users/darragh/Sites/so.php:0
Notice: Uninitialized string offset: 0 in /Users/darragh/Sites/so.php on line 26
Call Stack:
0.0002 227040 1. {main}() /Users/darragh/Sites/so.php:0
bool(false)
Example: https://eval.in/134971
Note that your notice PHP Notice: Uninitialized string offset: 0 is in there, amongst other things.
Either way, you should make your code robust, perhaps raise an exception or deal with the error in your preferred manner. Something like:
$uploadData = array_shift($check);
// die if the data is not an array or if it does not have the expected key
if (!is_array($uploadData) || !array_key_exists('type', $uploadData)) {
exit('$uploadData is not a valid array!');
}
// etc.
return !in_array($uploadData['type'], $imageTypes);
Example: https://eval.in/134972
Hope this helps.