protected and private keywords in php5

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
djrecker
Forum Newbie
Posts: 1
Joined: Thu May 27, 2010 4:52 am

protected and private keywords in php5

Post by djrecker »

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......
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: protected and private keywords in php5

Post by AbraCadaver »

mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply