Precisely. The point I was trying to make is that there should be fewer
restrictions on method names of classes so that developers that are
maintaining some distributable classes can keep the API clean. I've
found myself in a situation where instead of using a method call
isset(), I must use something like has().. and instead of unset(), I use
remove(). All the while, when I overload the __isset() and __unset()
methods, they actually forward the request to has() and remove().
I can think of several classes where the common sense method is a keyword:
$session->isset($variable);
$session->unset($variable);
$trash->empty();
$long_hallway->echo();
$stage->exit();
$baseball_player->catch();
$baseball_player->throw();
$game_of_life_member->die();
$wood->break();
$vegetarian->food->steak->try();
$lawyer->case->try(); // double fault ;)
Now I'm getting silly, but that was what my point was ;)
-ralph
Jochem Maas wrote:
Antony, I believe Ralph was using isset() and unset() purely
as arbitrary examples, e.g:
class TestReservedKeywordMethods
{
function unset() { echo "unset<br />"; }
function echo() { echo "echo<br />"; }
function empty() { echo "empty<br />"; }
}
$test = new TestReservedKeywordMethods();
$test->unset();
$test->echo();
$test->empty();
PS: the underlying example does work, which gives me the feeling that
it not so much an architechural limitation but rather a performance issue
with regard to doing extra checks as to the context of an encoutered
T_UNSET (for example) to determine whether it's okay, but I'm guessing
really - (and it's probably is not exactly what Ralph is looking for):
class TestReservedKeywordMethods
{
function __call($m) { echo "$m<br />"; }
}
$test = new TestReservedKeywordMethods();
$test->unset();
$test->echo();
$test->empty();
Antony Dovgal wrote:
__isset() and __unset() methods are what you're looking for.
They are available since 5.1.0.
See http://www.php.net/manual/en/language.oop5.overloading.php
On 10.05.2006 21:28, Ralph Schindler wrote:
Architectural restrictions aside, is it far off to ask if something
like this could be possible in PHP6:
<?
class TestReservedKeywordMethods
{
public $value = "2";
public function isset()
{
if (is_null($this->value))
return false;
else
return true;
}
public function unset()
{
$this->value = 0;
}
}
$test = new TestReservedKeywordMethods();
$test->isset();
$test->unset();
?>
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php