Jump to content

Recommended Posts

 

I recently installed WAMP5 from wampserver on my work PC (winXP) and have been stumped by a problem that I am assuming is some sort of issue between the wamp config and the OS config.

 

When I try to run the following code, instead of 'Bang!', I get 'bar(); ?>'. It seems that everything after the -> operator is ignored. Initially I though this was a newbie coding error, but I installed an identical wamp5 setup on my home PC (win2k) and everything works as it should on that system.

 

the code:

<?php
class foo {
public function bar() {
	print "Bang!\n";
}
}

$anInstance = new foo;
$anInstance -> bar();
?>

 

Can anyone suggest what OS settings, or security controls might cause this sort of behaviour?

Or any other potential cause.

 

thanks

 

Col

Link to comment
https://forums.phpfreaks.com/topic/73472-solved-php-ignoring-code-after-operator/
Share on other sites

That is wierd, Id'e try it without the space though, see how this goes.

 

White space shouldn't (and doesn't) make any difference.

 

Is outputting the rest of the code as text the normal PHP response to "I don't understand this code".

Or would it have to be something more specific like recognizing '->' as an alias of '?>' ?

 

Col

When you run that script right click and select view source, do you see your PHP source code? If you do then either WAMP is not configured correctly or you are not using the write file extension in order for WAMP to parse your PHP scripts.

 

I can confirm its a configuration issue as if I change the start php tag (<?php) to <? I get bar(); ?>. If I enabled short_open_tags then the code words as expected.

When you run that script right click and select view source, do you see your PHP source code? If you do then either WAMP is not configured correctly or you are not using the write file extension in order for WAMP to parse your PHP scripts.

I can see the source code when I open the file in a web browser and choose view source.

Wamp is using its defaults which work fine on my home system.

As far as file extensions, I'm using PHPeclipse on both systems with whatever extension it uses for php files.

I can confirm its a configuration issue as if I change the start php tag (<?php) to <? I get bar(); ?>. If I enabled short_open_tags then the code words as expected.

That's very useful to know - at least I can concentrate on the configuration, tyvm.

 

Col

 

How are you running the php script in the browser? Make sure you wamp is running and  you are going to http://locahost/ to run your script. Also make sure you save your script in C:/wamp/www/ (change the to path of where WAMP is installed to).

 

You can not run your PHP scripts directly through the browser, like you can with HTML files for example.

How are you running the php script in the browser? Make sure you wamp is running and  you are going to http://locahost/ to run your script. Also make sure you save your script in C:/wamp/www/ (change the to path of where WAMP is installed to).

 

You can not run your PHP scripts directly through the browser, like you can with HTML files for example.

 

I'll double check all that stuff tomorrow when I'm back on the work system. I did get it all working here on my home system with no trouble whatsoever - here I can run the php file from eclipse or through my browser directly using http://localhost/myfolder/myfile.php (I didn't even try C:\wamp\www\myfolder\myfile.php).

 

I've done a little php stuff in the past - setting up AMP by hand and heavily customizing some joomla plugin. But I don't 'know' php the way I know c++ and java in terms of how stuff works behind the scenes, so I don't have any intuition when things don't work as they should.

 

Thanks for your help, and I'll post back when I've had a chance to try some of these suggestions.

 

Col

 

 

It was down to me using the local file path rather than localhost  ::)

I still havn't got things working at I want in eclipse, but at least I can successfully run my php in an external browser, so I can get some work done.

 

Thanks for the help

 

Col

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.