0
<?php 
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

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by emarshah
0

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.

0

Hello,
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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.