mcsquiddy Posted March 20, 2012 Share Posted March 20, 2012 I am trying to create a very basic object but am having troubles. <?php class item{ public $name; public $price; function __construct($name,$price){ $this->name=$name; $this->price=$price;} function getName(){ return $this->name; } } $object = new item("car",400); echo $object->getName(); ?> The HTML output is: name=$name; $this->price=$price;} function getName(){ return $this->name; } } $object = new item("car",400); echo $object->getName(); ?> I'm sure that this code is clean but for some reason will not output the desired result! any help would be great. thanks. Quote Link to comment https://forums.phpfreaks.com/topic/259366-need-help-not-sure-what-is-wrong/ Share on other sites More sharing options...
Psycho Posted March 20, 2012 Share Posted March 20, 2012 That code is fine. The problem is the PHP in the file is not getting executed and is instead being returned to the browser without being processed. Are you loading the file in your browser directly? If so, you need to be "requesting" the file via a web server that has PHP installed and enabled. If that is what you are doing, does the file have an appropriate extension (i.e. 'php') that the web server has been configured to process for PHP scripts? Quote Link to comment https://forums.phpfreaks.com/topic/259366-need-help-not-sure-what-is-wrong/#findComment-1329598 Share on other sites More sharing options...
mcsquiddy Posted March 20, 2012 Author Share Posted March 20, 2012 I was using Xamp and now Wamp, I was running the files from the htdocs folder, Is there a better way to test my files?? thanks. Quote Link to comment https://forums.phpfreaks.com/topic/259366-need-help-not-sure-what-is-wrong/#findComment-1329600 Share on other sites More sharing options...
batwimp Posted March 20, 2012 Share Posted March 20, 2012 Are you sure you put it in the right directory? My WAMP uses the www directory for its stuff. Make sure your server is online, and you should be able to click on the icon in the tray and select wwwFolder, and that should take you to your root web directory. Quote Link to comment https://forums.phpfreaks.com/topic/259366-need-help-not-sure-what-is-wrong/#findComment-1329606 Share on other sites More sharing options...
mcsquiddy Posted March 20, 2012 Author Share Posted March 20, 2012 Got it working, I was being a moron. Thanks guys! Quote Link to comment https://forums.phpfreaks.com/topic/259366-need-help-not-sure-what-is-wrong/#findComment-1329607 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.