Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weird PHP Parse/Syntax errors with VMWare 6.5 + PHP 5.3.3 + Symfony 1.4

While following the "Practical Symfony" course, I have run in a strange error.

I have installed a Debian Squeeze in a VMWare 6.5.5 machine. It comes with PHP 5.3.3 and I am using Symfony 1.4. The source files are on the host, I am accessing them using the shared folder feature (vmhgfs mount).

Now, when I try the following commands, I get an error:

php symfony doctrine:build --model    
php symfony doctrine:build --sql

Error:

PHP Parse error:  syntax error, unexpected ')' in /var/www/appli/lib/model/doctrine/base/BaseJobeetJob.class.php on line 144

What is funny is that when I : - do the same thing without the shared folders (e.g. on a ext3 partition), it works, - convert the VM to VirtualBox and do the same thing on a shared folder, it works, - downgrade the PHP to 5.2.6 (from lenny), it works.

I remember having the same kind of issue some time ago with the PHP code generated by Smarty. As it was automatically generated PHP and could be regenerated at will, I had it generated in a local direcorty. But I do not think this is applicable to Doctrine generated files.

Does anyone have any clue of what is happening and how I could fix it ?

EDIT: here is the code around line 144:

    public function setUp()
    {
        parent::setUp();
        $this->hasOne('JobeetCategory', array(
             'local' => 'category_id',
             'foreign' => 'id',
             'onDelete' => 'CASCADE'));

        $timestampable0 = new Doctrine_Template_Timestampable();
        $this->actAs($timestampable0);
    }
} // Line 144 here.

It is actually the end of the file...

EDIT #2: to make it clear I have tested the following combinations in order to narrow down the issue:

  • VM software : VMWare Workstation 6.5.5 / VirtualBox 4.0.8
  • PHP version: 5.3.3 / 5.2.6,
  • Mount type : vmhgfs (or vboxsf with VirtualBox) / ext4 (local) / cifs (aka Windows share).

In every case I am using the very same source files (but for ext4 because I had no other choice than to copy them). I have a failure when combining the bold items. If I change any one of them, everything goes fine. I also tried to use the open-vm-modules in place of the provided vmware tools and to build a Debian installation from scratch instead of using my own automated script but neither has changed anything.

like image 494
Adirelle Avatar asked Jun 17 '11 09:06

Adirelle


People also ask

How do I fix parse error syntax error?

A parse error: syntax error, unexpected appears when the PHP interpreter detects a missing element. Most of the time, it is caused by a missing curly bracket “}”. To solve this, it will require you to scan the entire file to find the source of the error.

What is a PHP parse error?

If the PHP code contains a syntax error, the PHP parser cannot interpret the code and stops working. For example, a syntax error can be a forgotten quotation mark, a missing semicolon at the end of a line, missing parenthesis, or extra characters.


2 Answers

This seems to be a bug in vmhgfs - I have the same issue working with Drupal PHP code. It also seems to only happen when the files are added to the host from the guest, for example using git to clone a repository in the Linux VM.

There are three workarounds:

  1. Copy the files into their desired location, then disable shared folders in VMWare settings for the virtual machine, refresh the web page so you get 'Not found', then re-enable shared folders.

  2. On the host machine, run the following command which updates the file access / modified timestamps for every file, thus causing the VMWare driver to reload the file, fixing the issue:

    find . -exec touch {} \;
    
  3. Open the affected file from the host machine, modify it, and save it back. This may be useful if you're on a Windows machine.

The errors range from PHP Parse errors to others, normally flagging the last line of the file.

like image 96
Mark Theunissen Avatar answered Oct 13 '22 00:10

Mark Theunissen


I have the same problem on OpenSUSE 11.4 with PHP 5.3.5 using vmhgfs (on a Mac). I am also using doctrine, however I am using it without the full symfony project.

Initially vmhgfs didn't work at all, so I downloaded the open-vm-tools and compiled/installed that. That solved my problem for a few weeks, but it came back today.

The issue appears to be php reading past the end of the file. If I read the file with cat, less, or tail, then the end of the file looks fine.

tail of bad file

But if I do php -s bad_file.php > bad_file.php.html and look at the html output, I can see at the end of the file there is some extra garbage that I don't see with with cat, less, or vim.

php syntax highlighting of bad file

You can see that php sees "array (" at the end of the file, while other tools do not see that.

The only solution I've found is to manually add a new, blank line at the end of each problematic file. For some reason it only affects 1-2 files out of about 40.

like image 35
Mark E. Haase Avatar answered Oct 13 '22 01:10

Mark E. Haase