-1

In PHP, is there an alternative to the object operator, or a reason why the object operator won't work on a Windows/IIS environment?

I'm trying to migrate a PHP web application from Linux/Apache/MySQL to Windows/IIS/MySQL (IIS10, PHP 7.1.1) and it appears the object operator does not work in the Windows environment. In order to make portions of the site work I had to convert all array references from

$query_rs->id;

to

$query_rs['id'];

I'm also concerned about the use of the object operator for functions like

$Member->save();

and other object property access like

$this->id

Thanks for your time, I haven't found much information on this issue here or anywhere else on the web.

Jonas
  • 79
  • 10
  • 1
    Are there any errors in the server log that might offer any clues? – Paul T. Jul 13 '17 at 20:07
  • 1
    When you say it doesn't work what is happening? Objects and arrays are different and what you are showing is that the objects have become arrays. There's no reason that objects won't work in IIS, it's still php afterall. – Doug Jul 13 '17 at 20:07
  • 1
    Obviously this is an IIS bug. I never used it, i don't see why anyone else would use it unless for some strange reason your production servers are also windows. I'd recommend installing wamp or xampp. This is not really a solution, just a work around. Sorry for not being able to help you. – Lorenz V. Jul 13 '17 at 20:08
  • 1
    @LorenzV. I think "Don't use IIS" is a perfectly acceptable solution :) – WheatBeak Jul 13 '17 at 20:09
  • 2
    Do you use PDO? Did you checked the PDO settings? https://stackoverflow.com/a/4386731/1461181 – odan Jul 13 '17 at 20:10
  • 2
    I seriously doubt that IIS would automatically convert all objects to arrays. You simply have an array and not an object. – jeroen Jul 13 '17 at 20:11
  • So if you create a simple php file independent from your application, define and instantiate a simple object with one variable in it, then try to `echo $object->var;`, it won't work? – WheatBeak Jul 13 '17 at 20:11
  • @WheatBeak Of course that works :-) – jeroen Jul 13 '17 at 20:12
  • 1
    Also, what was the previous PHP version? There were some big changes moving from 5.x to 7.x that might need updating, if this is the situation. See this if it may be relevant: http://php.net/manual/en/migration70.php – Paul T. Jul 13 '17 at 20:13
  • Willing to bet that MySQL/pdo has simply been set to return associative arrays rather than objects. On the IIS argument, although I'm a Linux boy now to, I really see Nina reason not to use IIS it's good. – Doug Jul 13 '17 at 20:16
  • Ah so not all objects are broken. Only queries then? Maybe by reinstalling your project on windows, your composer packages updated to a newer version. And in that package they changed the return type of your query function. – Lorenz V. Jul 13 '17 at 20:18
  • Thank you for your comments and banter. It gave me a couple ideas and areas to research and test. – Jonas Jul 14 '17 at 17:17

1 Answers1

0

The PHP web application I'm migrating from Linux/Apache/MySQL (Apache 2.2, MySQL 5.5, PHP 5.4) to Windows/IIS/MySQL (Windows Server 2012, IIS 10, MySQL 5.5, PHP 7.1) uses the object operator -> to successfully access array items in .php files and in inline PHP code. In the new WIMP environment this does not work and causes a 500 Internal Server Error. I had to reconfigure all array references from the syntax

$query_rs->id;

to

$query_rs['id'];

before the application would work. I did many tests to isolate the issue and determined that other conventional uses of the object operator work as expected. I believe this is either an issue caused by the PHP version update or IIS because I've had some other issues with getting short open tags to work with IIS.

Jonas
  • 79
  • 10