Trying to get property 'id' of non-object only in my website - php

Recently I updated my website and I found this error only in one view, on my localhost works fine, I uploaded it via FTP. I'm going crazy!
[2020-01-30 03:32:39] local.ERROR: Trying to get property 'id' of non-object (View: /home/csinf298/resources/views/addEdit_promotion.blade.php) {"userId":3,"email":"email#email.com.mx","exception":"[object] (ErrorException(code: 0): Trying to get property 'id' of non-object (View: /home/csinf298/resources/views/addEdit_promotion.blade.php) at /home/csinf298/storage/framework/views/a22f101b5a2d4fafaa9530cd13c1077aebc547ce.php:211, ErrorException(code: 0): Trying to get property 'id' of non-object at /home/csinf298/storage/framework/views/a22f101b5a2d4fafaa9530cd13c1077aebc547ce.php:211)
My.blade
$promotion->id
I tried this too
$promotion->['id']
[2020-01-30 03:58:27] local.ERROR: Parse error: syntax error, unexpected '[', expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' (View: /home/csinf298/resources/views/addEdit_promotion.blade.php) {"userId":3,"email":"carlos.cisneros#csinformatica.com.mx","exception":"[object] (ErrorException(code: 0): Parse error: syntax error, unexpected '[', expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' (View: /home/csinf298/resources/views/addEdit_promotion.blade.php) at /home/csinf298/storage/framework/views/a22f101b5a2d4fafaa9530cd13c1077aebc547ce.php:176, Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Parse error: syntax error, unexpected '[', expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' at /home/csinf298/storage/framework/views/a22f101b5a2d4fafaa9530cd13c1077aebc547ce.php:176)

First of all, clear the caches with $promotion->id as using the below command.
php artisan config:cache
php artisan view:clear
php artisan route:clear
If you still get the error then use $promotion->userId as I have seen in your error the object contains userId, not an id.

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 (->).
or
Try This
$promotion->id
to
$promotion->['id']
or
$promotion[0]->poster['id']
$promotion->poster[0]['id']
It happen that after some time we need to run
php artisan passport:install --force
again to generate a key this solved my problem ,

Trying to get property 'id' of non-object
as you can see , it says non-object so you need to check 1st it's array or object if it is object then check id property is present or not
and if it is array then
rather then $promotion->['id']
use this
$promotion['id']

Related

How to fix Syntax error, unexpected '' (T_STRING)?

The error that I am receiving is this: Parse error: syntax error, unexpected 'TokenType' (T_STRING) in C:\Program Files\Ampps\www\cs5339\lepichardo\4339_f22_assignment1\TokenType.php on line 2. To be clear, both files are php, and they both are in the same director. The code below is where I include the enum TokenType so that I would be able to use it.
<?php
include 'TokenType.php'
?>
The TokenType.php looks like this
<?php
enum TokenType{
case INT;
case STRING;
case COMMA;
}
?>
As far as I now, this should be fine, but gives me that error in that particular line.
If there is any other way to declare and imlpement the enum variable in php I would like to be explained to how to. Thanks in advance!!!
enums are only available in PHP 8.1+. The error suggests you are running PHP 7.
Here's some results of running the following code using various PHP versions (using https://3v4l.org/qHU4f)
<?php
enum TokenType{
case INT;
case STRING;
case COMMA;
}
echo 'hello world';
Output for 8.1.0 - 8.1.11, 8.2rc1 - rc3
hello world
Output for 8.0.1 - 8.0.24
Parse error: syntax error, unexpected identifier "TokenType" in /in/qHU4f on line 2
Process exited with code 255.
Output for 7.4.0 - 7.4.32
Parse error: syntax error, unexpected 'TokenType' (T_STRING) in /in/qHU4f on line 2
Process exited with code 255.
As you can see by the last result, unexpected 'TokenType' (T_STRING) is an error you would receive in PHP 7

FatalThrowableError bootstrap/cache/services.php Laravel

Sometimes I am getting Errors from bootstrap/cache/services.php Laravel 5.6
And I don't understand why I am getting them and how to fix.
{"message":"syntax error, unexpected end of file, expecting ')'","class":"Symfony\\Component\\Debug\\Exception\\FatalThrowableError","code":0,"file":"\/app\/bootstrap\/cache\/services.php:130","line":0,"trace":"\/app\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/ProviderRepository.php:92; \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/ProviderRepository.php:55; \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/Application.php:548; \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/Bootstrap\/RegisterProviders.php:17; \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/Application.php:206; \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/Console\/Kernel.php:297; \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/Console\/Kernel.php:120; \/app\/artisan:35"}
or
{"message":"syntax error, unexpected ''command.queue.resta' (T_ENCAPSED_AND_WHITESPACE), expecting ')'","class":"Symfony\\Component\\Debug\\Exception\\FatalThrowableError","code":0,"file":"\/app\/bootstrap\/cache\/services.php:127","line":0,"trace":"\/app\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/ProviderRepository.php:92; \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/ProviderRepository.php:55; \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/Application.php:548; \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/Bootstrap\/RegisterProviders.php:17; \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/Application.php:206; \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/Console\/Kernel.php:297; \/app\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/Console\/Kernel.php:120; \/app\/artisan:35"}

Php how do i include # in variable

{
$myorganization->#type="Organization";//this point of view error
$myorganization->name="creative eyes";//this point of view error
}
whenever i save it on and run it shows
Parse error: syntax error, unexpected '#', expecting identifier
(T_STRING) or variable (T_VARIABLE) or '{' or '$' in
/srv/disk7/2375751/www/xyz.com/index.php on line 436
type is not variable in that instance, so you can't use it there.
You'd have to do: #$myorganization->type="Organization";//this point of view error

PHP: Why ERROR constant produces error?

I am using following code:
define ('EMPTY', 'test');
echo EMPTY;
But I am unable to get output. I am getting following Error:
Parse error: syntax error, unexpected ';', expecting '('
Empty is a reserved word.
<?php
define ('EMPTY2', 'test');
echo EMPTY2;
Works as intended.

PHP Bug? With Class?

Here is my code:
<?php class Video { protected $_test; } ?>
and when I try to include the file containing this code I've got that error:
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in ../classes/Video.class.php on line 1
What's wrong? I don't understand.
This looks like you're still running PHP 4, which doesn't know the protected keyword.
An update to PHP 5 would be a good idea.

Categories