class ShopProduct {

public $title;
public $content;

function __construct($title,$content) {
$this->title = $title;
$this->title = $content; }

function getProducer() 
{ return $this->title;
function getContent() 
{ return $this->content;

function foo() { echo "hello!";return 1;  }

// end class shop product

$product1 = new ShopProduct('Product 1','somegirls');
$product2 = new ShopProduct('Product 2','someguys');

print "this is {$product1->foo()}<br/>";
print "this is {$product1->getProducer()}<br/>";
print "this is {$product2->getContent()}<br/>";

the result is .
hello!this is 1
this is somegirls ( the content show ? why not the title ? )
this is ( the content dont show here . )

please help me on this two question . thanks .

Adam Ramadhan

This is the problem, your assigning the wrong variable.

function __construct($title,$content) {
$this->title = $title;
$this->title = $content; }

Change $this->title to $this->content, and it should work just fine.

everything is ok except

function __construct($title,$content) {
$this->title = $title;
$this->content = $content; }

Hope this will help you, whenever you find error, just go back from the print statement to the top of the code. You will find the error.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.