I have a class named DataBoundObject which is quite big. And works good. Its an ORM class i have developed. One of its functions is to automatically do the setXXX() and getXXX() functions so that no coding is required. The following function does that
public function __call($strFunction, $arArguments) {
$strMethodType = substr ( $strFunction, 0, 3 );
$strMethodMember = substr ( $strFunction, 3 );
if(!is_callable(array($this, $strFunction)))
throw new Exception("Function cannot be called!");
switch ($strMethodType) {
case "set" :
return ($this->SetAccessor ( $strMethodMember, $arArguments [0] ));
break;
case "get" :
return ($this->GetAccessor ( $strMethodMember ));
break;
default :
throw new Exception ( "Non existent method call dude!" );
}
return false;
}
Now in a class which derives this i override one function like this:
<?php
require_once ('DataBoundObject.php');
/**
* ORM extension of BUBBLES_HOTEL_REVIEWS Tabel
* @author footy
* @copyright Ajitah
*
*/
class reviews extends DataBoundObject {
protected $ReviewID;
//Other codes
private function setReviewID($ReviewID) {
throw new Exception ( "Cannot set the review ID Explicitly" );
}
//Other codes
//Other codes
//Other codes
//Other codes
//Other codes
}
$x = new reviews();
$x->setReviewID(5);
?>
Thus finally i create a new object and try to call setReviewID() function which is private. Why is it not generating any Exception? Besides is_callable() is returning true!
EDIT
Mainly i need help to correct this problem so that it throws an Exception
You can’t override private methods using __call magic in PHP. I allow myself to quote from php.net website http://php.net/language.oop5.visibility#92995, where your question is perfectly answered in a comment:
If you desperately need this feature – your (unconventional) options will be:
EDIT
Note that, protected child method is also hidden form the parent, but there is always an option of overriding __call() in a child. Generally, making too much “magical” overrides may be a bad taste for such a serious undertaken as ORM design.
PS
I believe eventually developing a DSL could be an ultimate goal for your project. Before doing so, continuing your project is a nice way to gather respective experience. GL!