Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Uncaught Error: Attempt to assign property on null

I was migrating a code from v7.4 to 8.0 and encountered this error on one of my page but was unable to solve it i know in php v8.0 this error will be encountered as written in migrating docs

error:

Fatal error: Uncaught Error: Attempt to assign property "allow_basic" on null in /homepages/5/d742909641/htdocs/payroll/Payroll/demo/demo/allowance_setup.php:77 Stack trace: #0 {main} thrown in /homepages/5/d742909641/htdocs/payroll/Payroll/demo/demo/allowance_setup.php on line 77

Code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

        $o1->allow_basic = implode("|", $allow_basic);
        $o10->allow_basic = implode("|", $allow_basic);

>Solution :

The error message is clear:

Attempt to assign property "allow_basic" on null

$o1 is null before you call $o1->allow_basic, which results in the error.

You have to define $o1 as a stdClass before using it:

$o1 = new stdClass();
$o1->allow_basic = 'foo';

Try it online

See the PHP documentation about stdClass: https://www.php.net/manual/en/class.stdclass.php#stdclass.properties-example

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading