[eluser]Reemon[/eluser]
EDIT: Oops, can someone tell me if this is the right forum for my post, thanks!
Hello
I'm learning OOP now at the moment. However in my book they talk about this class:
Product.php
Code:
<?php
class Product
{
protected $_type;
protected $_title;
public function __construct( $type, $title )
{
$this->_type = $type;
$this->_title = $title;
}
public function GetProductType()
{
return( $this->_type );
}
public function GetProductTitle()
{
return( $this->_title );
}
}
?>
Then I have another class:
Code:
<?php
require_once( 'product.php' );
class Book extends Product
{
protected $_PageCount;
public function __construct( $title, $pageCount )
{
$this->_title = $title;
$this->_PageCount = $pageCount;
$this->_type = 'Book';
}
public function GetPageCount()
{
return( $this->_PageCount );
}
}
?>
Then I have a normal file:
Code:
<?php
require_once( 'book.php' );
$product = new Book( 'Book', 'Learn PHP', 11 );
echo $product->GetProductTitle();
echo $product->GetProductType();
echo $product->GetPageCount();
?>
But it outputs:
Quote:BookBookLearn PHP
But the book says ( with the same code ) that it should output:
Quote:Learn PHPBook11
But it doesn't it only does if I use this class:
Code:
<?php
require_once( 'product.php' );
class Book extends Product
{
protected $_PageCount;
public function __construct( $type, $title, $pageCount )
{
$this->_title = $title;
$this->_PageCount = $pageCount;
$this->_type = 'Book';
}
public function GetPageCount()
{
return( $this->_PageCount );
}
}
?>
Watch the __constructor, I've added a new 'variable' in the function.
Could someone please help me please?
Thanks!