protected and private keywords in php5
Posted: Thu May 27, 2010 5:00 am
Hi everyone, If any one can please answer this one it will be really great....I am really confused....
I have the following files
1. oop.php
<?php
class emailer{
private $sender;
private $recepients;
private $subject;
private $body;
function __construct($sender)
{
echo "I was in construct";
$this->sender = $sender;
$this->recepients = array();
}
}
?>
2.subclass.php
<?php
class emailerExtended extends emailer{
public function setSender($sender)
{
$this->sender = $sender;
}
}
?>
3. userinh.php
<?php
include_once("oop.php");
include_once("subclass.php");
$xemailer = new emailerExtended("deepesh259nitk@gmail.com");
$xemailer->setSender("deepesh259nitk@gmail.com");
$xemailer->sender = "asdfwdf";
echo $xemailer->sender;
?>
when the sender variable is changed to protected it gives a fatal error. But when i run the above code as the way it is with private as sender it works...... :-0
Can someone please explain how this protected and private works......Also doesnt java and php5 and other oops concepts the basic access qualifiers same......
I have the following files
1. oop.php
<?php
class emailer{
private $sender;
private $recepients;
private $subject;
private $body;
function __construct($sender)
{
echo "I was in construct";
$this->sender = $sender;
$this->recepients = array();
}
}
?>
2.subclass.php
<?php
class emailerExtended extends emailer{
public function setSender($sender)
{
$this->sender = $sender;
}
}
?>
3. userinh.php
<?php
include_once("oop.php");
include_once("subclass.php");
$xemailer = new emailerExtended("deepesh259nitk@gmail.com");
$xemailer->setSender("deepesh259nitk@gmail.com");
$xemailer->sender = "asdfwdf";
echo $xemailer->sender;
?>
when the sender variable is changed to protected it gives a fatal error. But when i run the above code as the way it is with private as sender it works...... :-0
Can someone please explain how this protected and private works......Also doesnt java and php5 and other oops concepts the basic access qualifiers same......