Trying to get property 'action' of non-object
« Evo Parse Error »
Error : getimagesize(/.../assets/cache/images/assets/galleries/.../name1%282%29-300x300-ab0.jpg): failed to open stream: Нет такого файла или каталога
ErrorType[num] WARNING[2]
File /.../assets/snippets/simplegallery/sgLister.php
Line 57
Source $info = getimagesize(MODX_BASE_PATH.$data['thumb.'.$imageField]);
Backtrace
DocumentParser->executeParser()
index.php on line 139
DocumentParser->prepareResponse()
manager/includes/document.parser.class.inc.php on line 2863
DocumentParser->parseDocumentSource(string $var1)
manager/includes/document.parser.class.inc.php on line 2972
DocumentParser->evalSnippets(string $var1)
manager/includes/document.parser.class.inc.php on line 2718
DocumentParser->_get_snip_result(string $var1)
manager/includes/document.parser.class.inc.php on line 2028
DocumentParser->evalSnippet(string $var1, array $var2)
manager/includes/document.parser.class.inc.php on line 2116
eval()
manager/includes/document.parser.class.inc.php on line 1965
require(string $var1)
manager/includes/document.parser.class.inc.php(1965) : eval()'d code on line 1
DocumentParser->runSnippet('DocLister', array $var2)
assets/snippets/simplegallery/sgLister.php on line 70
DocumentParser->evalSnippet(string $var1, array $var2)
manager/includes/document.parser.class.inc.php on line 4335
eval()
manager/includes/document.parser.class.inc.php on line 1965
require(string $var1)
manager/includes/document.parser.class.inc.php(1965) : eval()'d code on line 1
DocLister->render()
assets/snippets/DocLister/snippet.DocLister.php on line 50
onetableDocLister->_render(string $var1)
assets/snippets/DocLister/core/DocLister.abstract.php on line 622
extDocLister->init(onetableDocLister $var1, array $var2)
assets/snippets/DocLister/core/controller/onetable.php on line 162
prepare_DL_Extender->run()
assets/snippets/DocLister/core/extDocLister.abstract.php on line 78
prepare_DL_Extender->callPrepare('DLsgLister::prepare', array $var2)
assets/snippets/DocLister/core/extender/prepare.extender.inc on line 52
DLsgLister::prepare(array $var1, DocumentParser $var2, onetableDocLister $var3, prepare_DL_Extender $var4)
assets/snippets/DocLister/core/extender/prepare.extender.inc on line 95
getimagesize(string $var1)
assets/snippets/simplegallery/sgLister.php on line 57
Имя картинки name1(2).jpg , загружена давным давно, и не было проблем до обновления на 1.4.11.
Photo from Unsplash
The PHP Notice: Trying to get property of non-object appears when your code tries to access a variable that’s not an object
type.
When accessing an object property, you need to use the property accessor syntax ->
as shown below:
// 👇 access the name property of user
$user->name;
But if the $user
variable is of another type, then PHP will show the notice:
<?php
$user = [
"name" => "Nathan",
];
// 👇 Notice: Trying to get property 'name' of non-object
print $user->name;
?>
The same happens when your $user
variable is of another type like a string
:
<?php
$user = "name: Nathan";
// 👇 Notice: Trying to get property 'name' of non-object
print $user->name;
?>
This PHP Notice can appear when you use vanilla PHP, WordPress, or Laravel to develop your application.
PHP doesn’t stop the script execution because of this notice, but the print
command will output nothing.
So if you have a code like this:
<?php
$user = [
"name" => "Nathan",
];
print "<h1>PHP output:</h1>";
print "<p>".$user->name."</p>";
print "<p>End</p>";
?>
The output will be:
The third print
line still gets printed even when the second fails.
To solve this issue, you first need to check the type of that non-object
variable.
Then, you need to adjust the variable accessor according to the type.
You can check a variable type using the var_dump()
function:
<?php
$user = [
"name" => "Nathan",
];
var_dump($user);
The output of var_dump()
will show the type of the $user
variable:
array(1) { ["name"]=> string(6) "Nathan" }
👆
variable type
If the variable is an object, then var_dump()
will show:
object(stdClass)#1 (1) { ["name"]=> string(6) "Nathan" }
In both outputs above, PHP uses the curly braces {}
before the elements and properties of array and object.
This is why people often mistake an array for an object. You need to pay attention to the left-most output instead of the content as shown below:
When the variable is an array
, you use the array element accessor []
instead of ->
like this:
<?php
$user = [
"name" => "Nathan",
];
print $user["name"]; // Nathan
?>
If it’s a string
, then access the variable using its name directly:
<?php
$user = "name: Nathan",
print $user;
To conclude, the PHP Notice: Trying to get property of non-object appears when you try to access a non-object variable like an object (using ->
to get the property value)
To solve this issue, you need to check the type of the variable and adjust the accessor accordingly.
Most of the time, you are mistaking an array for an object, so changing the accessor from ->
to []
should solve the issue:
<?php
$user = [
"name" => "Nathan",
];
// 👇 Change this
print $user->name;
// 👇 to this
print $user["name"];
?>
Don’t forget to add quotations around the array element name.
And that’s how you solve the PHP Notice: Trying to get property of non-object message. Good work! 👍
-
Access array value as array not object in PHP
<?php {{ $user['title'] }}
You have to use {{ $user[‘title’] }} instead of {{ $user->title }} to access the array value.
-
What does «Trying to get property of non object in..» mean?
The error occurs when you try to access a property of an object that isn’t an object. In this case you cannot access the property, as the $result isn’t an object. It is a boolean = false. One thing is to check that a variable is an object using PHP’s is_object.
-
What is the best solution for error «Trying to get property ‘title’ of non-object»?
Is your query returning array or object? If you dump it out, you might find that it’s an array and all you need is an array access ([]) instead of an object access (->).
-
Which of the following is not an object property?
foreach($po_items as $item){ if(is_null($item->vendor_company)){ continue } // do what you want with the vendor & vat_no. } A third option would be to query only the items that have a vendor company, assuming that there is a relationship involved in there.
-
How can I fix this error «Trying to get property ‘title’ of non-object»
Look like some users doesn’t have role .So better check for null.When you dd($user->roles->title) it only check for first user record not for all users.
@foreach($users as $user) <p> {{ $user->roles->title??null }} </p> @endforeach
-
How do you remove an object from a property?
You can use the delete operator to completely remove the properties from the JavaScript object. Deleting is the only way to actually remove a property from an object.
-
How can I find the object of a property?
We can check if a property exists in the object by checking if property !== undefined . In this example, it would return true because the name property does exist in the developer object.
Back to code snippet queries related laravel
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don’t forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.