class: protected methods

You can call protected class directly from another class
In the example below the class Club's method could call a protected member in a derived class; ( you won't be able to do it with private class). As a common feature of private and protected, you can't call directly any method with the instance/object created from the class.

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Add release form</title>
</head>

<body text="#FFFF00" bgcolor="#000080">

<form method="POST" action="protected_class.php5">

<p>Please your name and player's name <br> <input type="text" name="T1" size="20"><br/><input type="text" name="T2" size="20"><br/> <input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
<?php
$x = $_POST['T1'];
$y = $_POST['T2'];
if($x=="" or $y=="") { exit;}

class Club
{

public function editUser($username)
{
if(!$this->canedit())
{
print("Admin use only $y<br>\n");
return(FALSE);
}
//delete the user
print("Player Released:&nbsp;&gt; $username <br>\n");
}
}
class exceutives extends Club
{
protected function canedit()
{
print("protected called <br>");
return(TRUE);
}
}
$user = new Club;
$admin = new exceutives;
if ($x=="admin")
{ //authorized
$admin->editUser($y);
}
else
{
//not authorized
$user->editUser($y);
}

?>
</body>
</html>

 

if you try to call a protected class
$user = new Club;
$admin = new exceutives;
if ($x=="admin")
{ //authorized
//$admin->editUser($y);
$user->canedit($y);}
else