Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

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.
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

What's the question?  PHP Abstract classes are documented here:
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.
Avatar of rgb192

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
Show us some code examples that illustrate the issues, please.  Thanks, ~Ray
ASKER CERTIFIED SOLUTION
Avatar of Member_2_248744
Member_2_248744
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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();

Open in new window

Avatar of rgb192

ASKER

Absolute minimum requirements.  Thanks.