jairoh_
August 3rd, 2013, 12:53 AM
Good day everyone! I'm currently learning things up i have a question about extending a class.
On a file called MyClass.php there are two classes MyClass and the OtherClass that extends the Myclass and it works fine inheriting the superclass attributes.
<?php
class MyClass {
const CONST_VALUE = 'A constant value';
public function __construct () {
}
function index () {
return 'index';
}
function hello () {
return 'Hello';
}
}
class OtherClass extends MyClass {
function __construct() {
parent:: __construct();
}
function index () {
echo 'Other class index';
}
}
$OtherClass = new OtherClass();
echo $OtherClass->hello();
Output: "Hello"
but when i tried transferring the OtherClass into another module that extends the MyClass, it throws a server error. I don't wanna put it in the same module.
MyClass.php:
class MyClass {
const CONST_VALUE = 'A constant value';
public function __construct () {
//echo 'loaded constructor<br />';
}
function index () {
return 'index';
}
function hello () {
return 'Hello';
}
}
OtherClass.php:
class OtherClass extends MyClass {
function __construct() {
parent:: __construct();
}
function index () {
echo 'Other class index';
}
}
$OtherClass = new OtherClass();
$OtherClass->hello();
any help will be greatly appreciated from a beginner like me. thankyou. :)
On a file called MyClass.php there are two classes MyClass and the OtherClass that extends the Myclass and it works fine inheriting the superclass attributes.
<?php
class MyClass {
const CONST_VALUE = 'A constant value';
public function __construct () {
}
function index () {
return 'index';
}
function hello () {
return 'Hello';
}
}
class OtherClass extends MyClass {
function __construct() {
parent:: __construct();
}
function index () {
echo 'Other class index';
}
}
$OtherClass = new OtherClass();
echo $OtherClass->hello();
Output: "Hello"
but when i tried transferring the OtherClass into another module that extends the MyClass, it throws a server error. I don't wanna put it in the same module.
MyClass.php:
class MyClass {
const CONST_VALUE = 'A constant value';
public function __construct () {
//echo 'loaded constructor<br />';
}
function index () {
return 'index';
}
function hello () {
return 'Hello';
}
}
OtherClass.php:
class OtherClass extends MyClass {
function __construct() {
parent:: __construct();
}
function index () {
echo 'Other class index';
}
}
$OtherClass = new OtherClass();
$OtherClass->hello();
any help will be greatly appreciated from a beginner like me. thankyou. :)