Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP

oophp not working on xamp weird?

I want to experiment myself very first time following the video on OOPHP basic that was stage 2 related to method and properties. I was copying from their code into my file and i would like to check it out with my XAMP.

I turned on XAMP engine. I went to http://localhost/oop.php and got out of the blue.
It was error it said " Notice: Use of undefined constant ‘default_name’ - assumed '‘default_name’' in C:\xampp\htdocs\oop.php on line 13 Product Name: ‘default_name’"

I have noticed their URL were hampton.dev/ not using the localhost. hmm?

I do not know what does it mean?

The code is

<?php
class Product
{
    // properties
    public $name = ‘default_name’;

    //methods
    public function getInfo (){
        return "Product Name: ". $this->name;
    }
}

$p = new Product();
echo $p->getInfo(); 
?> 

2 Answers

Chris Shaw
Chris Shaw
26,650 Points

Hi Brian,

The problem is the fancy quotes in your code, currently you have the following.

public $name = ‘default_name’;

Instead it should be the following and it should work, as a reminder PHP requires correctly formatted single and double quotes as the parsing engine can't compile fancy quotes.

public $name = 'default_name';

wow you have an eagle eye! you are lucking caught the fish!