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
https://forums.phpfreaks.com/topic/259366-need-help-not-sure-what-is-wrong/
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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.