Why is it that getting a property of any PHP primitive data type does not trigger an error or warning?
Tried this on php 5.3.28:
$num = 1;
$str = 'hello';
$arr = array(1,2,3);
$nada = null;
$num->key1;
$str->key2;
$arr->key3;
$nada->key4;
No errors or warnings were triggered.
You don't have any error reporting enabled. When I run your code I see this:
PHP Notice: Trying to get property of non-object in /home/5BSpSI/prog.php on line 8
PHP Notice: Trying to get property of non-object in /home/5BSpSI/prog.php on line 9
PHP Notice: Trying to get property of non-object in /home/5BSpSI/prog.php on line 10
PHP Notice: Trying to get property of non-object in /home/5BSpSI/prog.php on line 11
Try running the code again, but add error_reporting(E_ALL); as the first line
Related
I updated w wordpress blog site to 6.0.1 and everything is okay except the post editing page doesn't load in (fatal error), when I use non english letters like "á".
If I create a new post and I write the content to "a" it is good.
Then if I change it to "á" it is bad.
If I deactivate the block editor in the user profile and I create a new post and I write "a" it is good.
If I then change it to "á" it is good.
Something is bad with the block editor.
The character coding of the tables and columns are utf8mb4_unicode_ci.
The php version is 7.4.
The MySQL version is 5.5.5-10.5.15-MariaDB.
Things I have tried:
deactivated every plugin
changed themes to twntytwentytwo
Notice:
Trying to access array offset on value of type null in blog/wp-content/plugins/wp-hide-post/admin/settings/class_settings.php
on line 324
Notice:
Undefined offset: 0 in blog/wp-includes/class-wp-block.php
on line 224
Notice:
Trying to get property 'parsed_block' of non-object in blog/wp-includes/class-wp-block.php
on line 228
Notice:
Trying to access array offset on value of type null in blog/wp-includes/block-supports/elements.php
on line 100
Notice:
Trying to get property 'parsed_block' of non-object in blog/wp-includes/class-wp-block.php
on line 233
Notice:
Trying to get property 'parsed_block' of non-object in blog/wp-includes/class-wp-block.php
on line 236
Notice:
Trying to access array offset on value of type null in blog/wp-includes/blocks/gallery.php
on line 20
Notice:
Trying to access array offset on value of type null in blog/wp-includes/blocks/latest-posts.php
on line 234
Notice:
Trying to access array offset on value of type null in blog/wp-includes/blocks/navigation.php
on line 666
Warning:
Creating default object from empty value in blog/wp-includes/class-wp-block.php
on line 236
Notice:
Undefined property: stdClass::$context in blog/wp-includes/class-wp-block.php
on line 239
Fatal error: Uncaught Error: Call to undefined method stdClass::render() in blog/wp-includes/class-wp-block.php:241
Stack trace:
#0 blog/wp-includes/blocks.php(901): WP_Block->render()
#1 blog/wp-includes/blocks.php(939): render_block(Array)
#2 blog/wp-includes/class-wp-hook.php(307): do_blocks('
I am getting this PHP error:
Notice: Undefined offset: 0 in D:\MYBLOG\InstantWP_4.3.1\iwpserver\htdocs\wordpress\wp-content\themes\MYBLOG\admin\library\engines\typography-engine.php on line 32
Notice: Undefined offset: 1 in D:\MYBLOG\InstantWP_4.3.1\iwpserver\htdocs\wordpress\wp-content\themes\MYBLOG\admin\library\engines\typography-engine.php on line 32
Here is the PHP code that throws it:
/* Check stored against current to make sure we don't display deleted css */
if(is_array($custom_fonts)):
foreach($custom_fonts as $id => $font):
if(!$current_custom[$id])unset($custom_fonts[$id]);
endforeach;
endif;
$css = '';
LINE 32 IS HERE:
if(!$current_custom[$id])unset($custom_fonts[$id]);
What does this error mean? What causes this error?
Is there a quick fix to resolve these error?
Really appreciate for any help
Thank you
Replace the 32 line with this:
if(empty($current_custom[$id]) || !$current_custom[$id])unset($custom_fonts[$id]);
There is not a real problem, only a notice (=advice, not error, not warning) which tells you that the $id does not actually exists in the $current_custom array. As the coded tries to unsed the $current_custom[$id] if it is evaluated as false (null, zero, empty string, ...) it is just fine.
Can anyone help me with this error? When running the site on my host i get no errors but when i run it with xampp on my pc i get this
Notice: Undefined offset: 1 in C:\xampp1\htdocs\ctcoun1kk\countrycheck.php on line 273
Notice: Undefined offset: 2 in C:\xampp1\htdocs\ctcoun1kk\countrycheck.php on line 273
Notice: Undefined offset: 3 in C:\xampp1\htdocs\ctcoun1kk\countrycheck.php on line 273
Line 273 is this one->
$decip = ($numbers[0]*16777216)+($numbers[1]*65536)+($numbers[2]*256)+($numbers[3]);
function x_dot2dec($dotip) {
$numbers = preg_split( "/./", $dotip);
$decip = ($numbers[0]*16777216)+($numbers[1]*65536)+($numbers[2]*256)+($numbers[3]);
return array ($decip, $numbers[0]);
}
Thank you for any help :)
It means that $numbers variable is not set properly. Before 273 line put:
var_dump($numbers);
and check if indexes 0,1,2 and 3 are set
Those are just notices. The script should work fine if you ignore thos. Set error reporting level using error_reporting (http://www.php.net/manual/en/function.error-reporting.php) and those will go away. This is set on your other server- that's why you don't see these "errors".
error_reporting(0); //disable all errors and notices
I am using PHP for the first time. I am using the php sample for uploading image on ebay sandbox. I am getting the following error on running the PHP file:
PHP Warning: simplexml_load_string(): Entity: line 1: parser error : Start tag expected, '<' not found in /home/nish/stuff/market place/test/php5/UploadImage/UploadSiteHostedPictures.php on line 69
PHP Warning: simplexml_load_string(): HTTP/1.1 200 OK in /home/nish/stuff/market place/test/php5/UploadImage/UploadSiteHostedPictures.php on line 69
PHP Warning: simplexml_load_string(): ^ in /home/nish/stuff/market place/test/php5/UploadImage/UploadSiteHostedPictures.php on line 69
PHP Notice: Trying to get property of non-object in /home/nish/stuff/market place/test/php5/UploadImage/UploadSiteHostedPictures.php on line 92
PHP Notice: Trying to get property of non-object in /home/nish/stuff/market place/test/php5/UploadImage/UploadSiteHostedPictures.php on line 93
PHP Notice: Trying to get property of non-object in /home/nish/stuff/market place/test/php5/UploadImage/UploadSiteHostedPictures.php on line 93
PHP Notice: Trying to get property of non-object in /home/nish/stuff/market place/test/php5/UploadImage/UploadSiteHostedPictures.php on line 94
PHP Notice: Trying to get property of non-object in /home/nish/stuff/market place/test/php5/UploadImage/UploadSiteHostedPictures.php on line 94
Relevant lines are:
69. $respXmlObj = simplexml_load_string($respXmlStr); // create SimpleXML object from string for easier parsing
// need SimpleXML library loaded for this
92. $ack = $respXmlObj->Ack;
93. $picNameOut = $respXmlObj->SiteHostedPictureDetails->PictureName;
94. $picURL = $respXmlObj->SiteHostedPictureDetails->FullURL;
What I can understand is the respXMLObj is not getting set properly. I have checked that simleXML support is enabled.
Could someone please help me debug this. Thanks
The code you refer to has this line:
//curl_setopt($connection, CURLOPT_HEADER, 1 ); // Uncomment these for debugging
it seems like you uncommented these. This will result in getting the HTTP header in your response. Which is OK for debugging, but it will create an XML parse error in simplexml_load_string.
Either comment it out again or put 0 as its value.
In my case. I just removed the invisible character The BOM in the beginning of the XML file. How to do it - depends on your text editor.
$hasError = false;
if ( $resp == 'Internal Server Error' || empty($resp) )
{
$hasError = true;
}
if ( ! $hasError )
{
$aux = !empty($resp) ? explode('', $resp) : NULL;
$temp = utf8_decode(trim($aux[0]));
$xml = simplexml_load_string($temp);
}
Do a var_dump($respXmlStr); my guess is that this string is not valid XML.
As per the simplexml-load-string documentation, the first parameter is expected to be A well-formed XML string - http://php.net/manual/en/function.simplexml-load-string.php
This is in Drupal but should be applicable for normal PHP.
field-event-address is an array that is under $entity_fetched.
<?php if ($entity_fetched->field-event-address != "") echo $entity_fetched->field-event-address['und']['0']['value']; ?>
For some reason, when I do this, I get this error if I leave the ['und']['0']['value'] off:
Notice: Undefined property: stdClass::$field in eval() (line 7 of /opt/staging/contitemp/public_html/sites/all/modules/rules/modules/php.eval.inc(125) : eval()'d code).
Notice: Use of undefined constant event - assumed 'event' in eval() (line 7 of /opt/staging/contitemp/public_html/sites/all/modules/rules/modules/php.eval.inc(125) : eval()'d code).
Notice: Use of undefined constant address - assumed 'address' in eval() (line 7 of /opt/staging/contitemp/public_html/sites/all/modules/rules/modules/php.eval.inc(125) : eval()'d code).
And this error if I leave it on:
Parse error: syntax error, unexpected '[', expecting ',' or ';' in /opt/staging/contitemp/public_html/sites/all/modules/rules/modules/php.eval.inc(125) : eval()'d code on line 7
I am trying to create an if statement that checks to see if the array under the object is empty or not, and if it isn't, echos the array contents.
I'm really scratching my head with this one - I should be able to just check if an array is empty if it's under an object, correct?
- sign can't be used in variables names in PHP. Because of that you're getting syntax error (or undefined constant when PHP is trying to understand what did you mean).
Instead you can change name to $entity_fetched->fieldEventAddress (it's still readable and now it's correct).
For Drupal, you really should be using entity metadata wrappers.
So your code would be something like:
$wrapper = entity_metadata_wrapper('entity_type', $fetched_entity);
$value = $wrapper->field_name->value();
if (!empty($value)) echo $value;
You can find more information about entity metadata wrappers here:
https://drupal.org/node/1021556