VMWare 6.5 出现奇怪的 PHP 解析/语法错误PHP 5.3.3 +交响乐1.4

发布于 2024-11-16 01:24:06 字数 1597 浏览 7 评论 0原文

在学习“Practical Symfony”课程时,我遇到了一个奇怪的错误。

我在 VMWare 6.5.5 机器上安装了 Debian Squeeze。它附带 PHP 5.3.3,我使用的是 Symfony 1.4。源文件位于主机上,我使用共享文件夹功能(vmhgfs 安装)访问它们。

现在,当我尝试以下命令时,出现错误:

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

错误:

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

有趣的是,当我: - 在没有共享文件夹的情况下执行相同的操作(例如在 ext3 分区上),它可以工作, - 将虚拟机转换为 VirtualBox 并在共享文件夹上执行相同的操作,它可以工作, - 将 PHP 降级到 5.2.6(来自 lenny),它可以工作。

我记得不久前 Smarty 生成的 PHP 代码也遇到过同样的问题。由于它是自动生成的 PHP 并且可以随意重新生成,因此我在本地目录中生成了它。但我认为这不适用于 Doctrine 生成的文件。

有谁知道发生了什么以及我该如何解决它?

编辑:这里是第 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.

它实际上是文件的末尾...

编辑#2:为了明确起见,我已经测试了以下组合以缩小问题范围:

  • VM 软件:VMWare工作站 6.5.5 / VirtualBox 4.0.8
  • PHP 版本:5.3.3 / 5.2.6,
  • 安装类型:vmhgfs(或带有 VirtualBox 的 vboxsf)/ ext4 (当地的) /cifs(又名 Windows 共享)。

在每种情况下,我都使用完全相同的源文件(但对于 ext4,因为我除了复制它们之外别无选择)。我在组合粗体项目时失败了。如果我改变其中任何一个,一切都会顺利。我还尝试使用 open-vm-modules 代替提供的 vmware 工具,并从头开始构建 Debian 安装,而不是使用我自己的自动化脚本,但两者都没有改变任何东西。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

腻橙味 2024-11-23 01:24:06

这似乎是 vmhgfs 中的一个错误 - 我在使用 Drupal PHP 代码时也遇到同样的问题。这似乎也只有当文件从来宾添加到主机时才会发生,例如使用 git 克隆 Linux 虚拟机中的存储库。

共有三种解决方法:

  1. 将文件复制到所需位置,然后在虚拟机的 VMWare 设置中禁用共享文件夹,刷新网页以便显示“未找到”,然后重新启用共享文件夹。

  2. 在主机上,运行以下命令,更新每个文件的文件访问/修改时间戳,从而导致 VMWare 驱动程序重新加载文件,从而解决问题:

    <前><代码>查找 . -exec touch {} \;

  3. 打开受影响的文件从主机,修改它,然后保存回来。如果您使用的是 Windows 计算机,这可能很有用。

错误范围从 PHP 解析错误到其他错误,通常标记文件的最后一行。

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.

一萌ing 2024-11-23 01:24:06

我在使用 vmhgfs(在 Mac 上)的 OpenSUSE 11.4 和 PHP 5.3.5 上遇到同样的问题。我使用学说,但是我在没有完整的 symfony 项目的情况下使用它。

最初 vmhgfs 根本不起作用,所以我下载了 open-vm-tools 并编译/安装了它。这解决了我几个星期的问题,但今天又回来了。

问题似乎是 php 读取到了文件末尾。如果我用 cat、less 或 tail 读取文件,那么文件末尾看起来不错。

tail of bad file

但是如果我这样做 php -s bad_file.php > bad_file.php.html 并查看 html 输出,我可以看到在文件末尾有一些额外的垃圾,这是我在 cat、less 或 vim 中看不到的。

php bad file 语法高亮

可以看到php在文件末尾看到了“array(”,而其他工具 我发现

的唯一解决方案是在每个有问题的文件末尾手动添加一个新的空白行,由于某种原因,它只影响大约 40 个文件中的 1-2 个。

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.

失退 2024-11-23 01:24:06

这里同样的问题。我确认这是 vmhgfs 问题。
解决方法是使用 NFS 共享而不是 vmware 共享文件夹:

Linux env

apt-get install portmap nfs-common nfs-kernel-server

mkdir /nfs-share1
echo "/nfs-share1 192.168.2.1(rw,sync)" >> /etc/exports

/etc/init.d/portmap start
/etc/init.d/nfs-kernel-server start
/etc/init.d/nfs-common start

usermod -u 501 paolo
find / -user paolo -exec chown paolo {} \;

OS X env

showmount -e 192.168.2.129

mkdir /Users/paolo/netshare1
mount -t nfs -o resvport,soft,intr,rsize=8192,wsize=8192,timeo=900,retrans=3,proto=tcp 192.168.2.129:/nfs-share1 /Users/paolo/netshare1/

Same problem here. I confirm that it is a vmhgfs problem.
A workaround is to use a NFS share instead of vmware shared folders:

Linux env

apt-get install portmap nfs-common nfs-kernel-server

mkdir /nfs-share1
echo "/nfs-share1 192.168.2.1(rw,sync)" >> /etc/exports

/etc/init.d/portmap start
/etc/init.d/nfs-kernel-server start
/etc/init.d/nfs-common start

usermod -u 501 paolo
find / -user paolo -exec chown paolo {} \;

OS X env

showmount -e 192.168.2.129

mkdir /Users/paolo/netshare1
mount -t nfs -o resvport,soft,intr,rsize=8192,wsize=8192,timeo=900,retrans=3,proto=tcp 192.168.2.129:/nfs-share1 /Users/paolo/netshare1/
北城半夏 2024-11-23 01:24:06

啊!最后我想通了。我在 Mac OS X Lion (10.7.2) 上使用 VMware Fusion (4.0.2),并且一直在绞尽脑汁地试图解决这个问题。

升级您的 VMware 工具!

到目前为止,一切顺利:没有再次遇到该问题。目前最新版本是 VMware Tools 8.0.0。

Ugh! Finally I figured it out. I'm using VMware Fusion (4.0.2) on Mac OS X Lion (10.7.2) and I've been pulling my hair out trying to figure this out.

Upgrade your VMware Tools!

So far, so good: Haven't encountered the problem again. The latest release at this time is VMware Tools 8.0.0.

过气美图社 2024-11-23 01:24:06

好吧,这可能偏离主题,但我希望它有所帮助:
我正在写同一本书,并且我已经这样做了(我认为你最好像我一样做一些事情):

  • 在 VirtualBox 中安装 Ubuntu 服务器
  • 在 Ubuntu 上安装 LAMP 服务器
  • 安装 vsftpd,用于 Ubuntu 上的 ftp 访问
  • 在 Ubuntu 上安装 SSH 服务器。

现在,如果我在 Linux 主机上,我会使用具有 ftp 访问权限的 Aptana Studio 来编辑文件,并使用 SSH 来运行命令,如果我在 Windows 主机上,我会使用 Aptana Studio 和 Putty 进行 SSH 访问。

如果你做类似的事情,你可能不会有任何麻烦。
希望有帮助。

Well, this might be off topic, but I hope it helps:
I am working on the same book, and I have done this (I think you'd better do something like me):

  • Installed Ubuntu Server inside VirtualBox
  • Installed LAMP Server on Ubuntu
  • Installed vsftpd, for ftp access on Ubuntu
  • Installed SSH server on Ubuntu.

Now, if I am on Linux host, I use Aptana Studio with ftp access for editing files and SSH to run commands, and if I am on Windows, I use Aptana Studio and Putty for SSH access.

If you do something similar, you will probably have no trouble.
Hope it helps.

羞稚 2024-11-23 01:24:06

我在 WordPress 和 Laravel 上也遇到了这个问题。要解决此问题,我必须从来宾重新安装已安装的文件夹。

例如,我的所有源文件都位于主机 (OSX) 上,并通过 vmhgfs 共享到 Ubuntu(来宾)。挂载点为/mnt/hgfs/www。重新安装:

sudo mount /mnt/hgfs/www

I am also experiencing this problem in regards to Wordpress and Laravel. To fix the problem, I have to remount the mounted folder from the guest.

For instance, all my source files are located on the host (OSX) and shared to Ubuntu (guest) with vmhgfs. The mount point is /mnt/hgfs/www. To remount:

sudo mount /mnt/hgfs/www
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文