Jump to content

Need help, not sure what is wrong.


mcsquiddy

Recommended Posts

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.

 

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.