rgb192
asked on
abstract class property and method
abstract class shape{
private $_property1
protected method1(){}
}
any class that extends abstract class shape
does not require properties
and depending upon when I do private,protected,public method
I get error must be visibility or better
please explain.
private $_property1
protected method1(){}
}
any class that extends abstract class shape
does not require properties
and depending upon when I do private,protected,public method
I get error must be visibility or better
please explain.
ASKER
questions are
1)
if I set properties in the parent class, why dont the children require the same properties
2)
and setting methods in the child class
what is the
must be visibility or better
error
1)
if I set properties in the parent class, why dont the children require the same properties
2)
and setting methods in the child class
what is the
must be visibility or better
error
Show us some code examples that illustrate the issues, please. Thanks, ~Ray
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I *think* I understand the problem but don't know the explanation.
PHP seems to complain about a *private* member in an *abstract* class which should not be a problem at all, maybe a warning if it is completely unused.
PHP seems to complain about a *private* member in an *abstract* class which should not be a problem at all, maybe a warning if it is completely unused.
This worked correctly for me. If you have an example that is failing, please post it so we can be looking at exactly the same thing you're looking at, thanks.
<?php // RAY_temp_foo.php
error_reporting(E_ALL);
abstract class Shape
{
private $_property1;
protected function method1(){}
}
class Square extends Shape
{
public function method1()
{
echo 'Square';
}
}
$sq = new square;
$sq->method1();
ASKER
Absolute minimum requirements. Thanks.
http://php.net/manual/en/language.oop5.abstract.php
The abstract class definition forces the programmer to extend the class, rather than to instantiate the class.