CodeIgniter Forums
On new server error: "Trying to get property of non-object" - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: On new server error: "Trying to get property of non-object" (/showthread.php?tid=3023)



On new server error: "Trying to get property of non-object" - El Forum - 09-05-2007

[eluser]ortsanfang[/eluser]
Today I moved my application to a new server and since hours I can't figure out what's wrong.

1. On the old server (Apache 2, PHP 4.3.10-22, MySQL 4.0.24) everything is fine.

2. On the new server - with the same code and database - I get many "A PHP Error was encountered: Trying to get property of non-object" errors. (Apache 2. PHP 5.2.0-8+etch7, MySQL 5.0.32). The errors occur (as I can see) whenever I use validation constructions like

Code:
<?=($this->validation->priv_phone) ? ($this->validation->priv_phone) : ($contact_data->priv_phone);?>

3. To check if there's a problem with my new server's configuration I installed XAMPP (http://www.apachefriends.org / Apache 2, PHP 5.2.1, MySQL 5.0.37) on my local Linux machine. Same problems.

Any hints, what can be wrong? I'm confused because in all cases it's the same code.


On new server error: "Trying to get property of non-object" - El Forum - 09-05-2007

[eluser]coolfactor[/eluser]
I'd look at getting that PHP 5 version updated. It's slightly old and there were known problems in the 5.2.0 distribution. It's possible it's not passing and setting variables correctly in the view.


On new server error: "Trying to get property of non-object" - El Forum - 09-05-2007

[eluser]ortsanfang[/eluser]
So I need to compile PHP myself on the Debian Etch server? Do you now a good tutorial where this is explained step by step?


On new server error: "Trying to get property of non-object" - El Forum - 09-05-2007

[eluser]ortsanfang[/eluser]
Switched in XAMPP to PHP4 and everything is immediately right. Coolfactor, I'm pretty sure, that your assumption is correct; though I wonder, why nobody else has troubles with 5.2.x. Nobody running Debian Etch?


On new server error: "Trying to get property of non-object" - El Forum - 09-05-2007

[eluser]ortsanfang[/eluser]
Upgraded to 5.2.3 without success: same errors as in 5.2.0 und 5.2.1 :-(

Is it possible that there's a compatibility issue with CodeIgniter an these PHP versions?


On new server error: "Trying to get property of non-object" - El Forum - 09-05-2007

[eluser]coolfactor[/eluser]
[quote author="ortsanfang" date="1189043680"]Upgraded to 5.2.3 without success: same errors as in 5.2.0 und 5.2.1 :-(

Is it possible that there's a compatibility issue with CodeIgniter an these PHP versions?[/quote]

Not sure what to suggest. However, I would avoid shortcuts and the awkward code you have here:

Code:
<?=($this->validation->priv_phone) ? ($this->validation->priv_phone) : ($contact_data->priv_phone);?>

1. don't use the short tags
2. you don't need brackets around atomic values

I'd write it like so:
Code:
<?php echo ($this->validation->priv_phone ? $this->validation->priv_phone : $contact_data->priv_phone); ?>

I doubt that's the source of the problem, but it was worth a shot.


On new server error: "Trying to get property of non-object" - El Forum - 09-06-2007

[eluser]ortsanfang[/eluser]
Coolfactor, thank you very much for your support. Unfortunately, changing the code as suggested didn't solve the problem. Is there a PHP setting which can prevent corret variable passing?