Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialBram Huisman
7,387 PointsLocal php development.. no document found?
Hi guys,
I have a silly question -.- I'm following the PHP beginner track.. i don't like the workspace, so i work in sublime!
I'm using MAMP as my localhost but.. when i open it.. there is no document at all? There is only one file in the folder (index.php)..
And this code is in it:
<?php class = Product{
public $name = 'default_name';
public $price = '0';
public $desc = 'default description';
function __construct($name, $price, $desc){
$this->name = $name;
$this->price = $price;
$this->desc = $desc;
}
public function getInfo(){
return "Default name: ". this->name;
}
}
$shirt = new Product("Space juice t-shirt", "20", "lololol"); echo $shirt->getInfo();
?>
What am i doing wrong? Sorry if my english is incorrect
4 Answers
Ted Sumner
Courses Plus Student 17,967 PointsI see the problem. You need a $ in front of this.
Ted Sumner
Courses Plus Student 17,967 PointsIs your project stored in the proper MAMP folder and is the server turned on?
Bram Huisman
7,387 PointsYep, in the proper MAMP folder.. i run some wordpress websites on the same MAMP folder. And yes the server is running
Bram Huisman
7,387 PointsAh, i have tested it with a simple: echo "hello, world"; and it works.. Is there a problem in my code?
<?php
class Product
{
public $name = 'default_name';
public $price = 0;
public $desc = 'default description';
function __construct($name, $price, $desc){
$this->name = $name;
$this->price = $price;
$this->desc = $desc;
}
public function getInfo(){
return "Product name: ". this->name;
}
}
$shirt = new Product("Space Juice T-shirt", 20, "Awesome Grey T-shirt");
$soda = new Product("Space Juice Soda", 2, "graph flavored thirst modulator");
echo $shirt->getInfo();
?>
Ted Sumner
Courses Plus Student 17,967 PointsI don't see an error but I will try the code when I am not on my iPad.
Bram Huisman
7,387 PointsBram Huisman
7,387 PointsThx Ted, it's working now! :D