0

I have a strange problem with creating dynamic objects.

On my local server with PHP 5.3.10-1ubuntu3.8 this code works fine:

$sObjName = 'field_xyz';
$o = $oVendor->{$sObjName};
print_r($o);                //prints the object "$oVendor->field_xyz"

But on my live server with PHP 5.3.13 the same code doesnt work. I cant create a dynamic object.

This code also doesnt work on my live server:

$oVendor->$sObjName

Otherwise this code works on both servers:

$a = "Hello";
$$a = "World";
echo "$a ${$a}";      //prints out "Hello World"

I would guess that this is a php.ini setting problem but I really dont know.

Local Server vs: Live Server

Local:

  • Real Server
  • PHP 5.3.10-1ubuntu3.8
  • Suhosin Patch 0.9.10
  • Apache/2.2.22 (Ubuntu)

Live:

  • Virtual Server
  • PHP 5.3.13
  • No Suhosin
  • Apache/2.2.16 (Debian) PHP/5.3.13 mod_ssl/2.2.16 OpenSSL/0.9.8o
jb7AN
  • 77
  • 1
  • 6
  • If that code doesn't work on your live server then something is seriously broken. – Jon Dec 17 '13 at 13:10
  • 3
    [**Can't confirm**](http://3v4l.org/N7EoG). What *doesn't* work? Do you get an error? Does it silently fail? Does it crash PHP? Does your server force reboot? – h2ooooooo Dec 17 '13 at 13:11
  • What's different between your test and production systems? PHP versions? Suhosin?.... – symcbean Dec 17 '13 at 13:39
  • @h2ooooooo There is no error and no notice and no php crash. My live server just doesnt create this new object and so the print_r() prints nothing. – jb7AN Dec 17 '13 at 14:22
  • @user3111283 What does `var_dump` output? `var_dump` ALWAYS has to output something. Whether it's NULL, false, true, etc. etc. Do you have `error_reporting(E_ALL)` on? – h2ooooooo Dec 17 '13 at 14:30
  • @symcbean I edited the original post for differences – jb7AN Dec 17 '13 at 14:38
  • @h2ooooooo Yes i have "E_ALL". `var_dump($oVendor->{$sObjName})` outputs "NULL" – jb7AN Dec 17 '13 at 14:44
  • @user3111283 And `var_dump($oVendor)`? (update OP with it) – h2ooooooo Dec 17 '13 at 14:45
  • @h2ooooooo Ohh i feel very stupid right now. `var_dump($oVendor)` showed me that the object `$oVendor->field_xyz` is "NULL" in my live system and not an own object like in my local system. Its an application problem – jb7AN Dec 17 '13 at 14:53
  • @user3111283 No worries - it's what we're here for. `var_dump` is **incredibly** useful for debugging. I use it all the time. – h2ooooooo Dec 17 '13 at 15:06

0 Answers0