note 98411 added to function.call-user-func-array
| From: | CarstenMilkau at osu1 dot php dot net | Date: | Mon, 14 Jun 2010 13:39:24 +0000 |
| Subject: | note 98411 added to function.call-user-func-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-170114@lists.php.net to get a copy of this message | ||
What is the *proper* way to do something like this? (In short: I want a class to hide the class
constructor for all but a few chosen friend classes)
<?php
class PackageClass
{
static protected function _new($class, $args)
{
switch (count($args))
{
case 0:
return new $class();
break;
case 1:
return new $class($args[0]);
break;
case 2:
return new $class($args[0], $args[1]);
break;
case 3:
return new $class($args[0], $args[1], $args[2]);
break;
case 4:
return new $class($args[0], $args[1], $args[2], $args[3]);
break;
case 5:
return new $class($args[0], $args[1], $args[2], $args[3], $args[4]);
break;
case 6:
return new $class($args[0], $args[1], $args[2], $args[3], $args[4], $args[5]);
break;
}
}
}
class UnconstructibleClass extends PackageClass
{
protected function __construct($msg)
{
print($msg);
}
}
class ConstructingClass extends PackageClass
{
public function __construct()
{
self::_new(UnconstructibleClass, array("Und ich krieg dich doch!"));
}
}
new ConstructingClass();
?>
----
Server IP: 85.214.154.209
Probable Submitter: 217.17.195.26
----
Manual Page -- http://www.php.net/manual/en/function.call-user-func-array.php
Edit -- https://master.php.net/note/edit/98411
Del: integrated -- https://master.php.net/note/delete/98411/integrated
Del: useless -- https://master.php.net/note/delete/98411/useless
Del: bad code -- https://master.php.net/note/delete/98411/bad+code
Del: spam -- https://master.php.net/note/delete/98411/spam
Del: non-english -- https://master.php.net/note/delete/98411/non-english
Del: in docs -- https://master.php.net/note/delete/98411/in+docs
Del: other reasons-- https://master.php.net/note/delete/98411
Reject -- https://master.php.net/note/reject/98411
Search -- https://master.php.net/manage/user-notes.php