What are the values of $a in $obj_one and $obj_two when this script is executed?
<?php
class myClass {
private $a;
public function __construct() {
$this->a = 10;
}
public function printValue() {
print "The Value is: {$this->a}\n";
}
public function changeValue($val, $obj = null) {
if(is_null($obj)) {
$this->a = $val;
} else {
$obj->a = $val;
}
}
public function getValue() {
return $this->a;
}
}
$obj_one = new myClass();
$obj_two = new myClass();
$obj_one->changeValue(20, $obj_two);
$obj_two->changeValue($obj_two->getValue(), $obj_one);
$obj_two->printValue();
$obj_one->printValue();
?>
Answer...
10,20
You cannot modify private member variables of a different class
20,20
10,10
20,10
MY ans: 20, 20
Please answer through the comments I will make it publish on blog..............
[Thursday, February 21, 2008
|
0
comments
]
Popular Posts
- php questions
- some php questions
- How to create a plugin in elgg.
- php Questions
- Mysql query for searching a value, add weightage on the number of occurances and sort based on the weight-age
- Contact Me
- solving the packaging problem in PHP
- How to add or remove WWW on URLs using htaccess.
- php questions
- Inserting nodes into xml files using XML DOM in PHP .
0 comments
Post a Comment
Please put your comments here. your questions, your suggestions, also what went wrong with me.