note 56485 added to language.oop5
| From: | arek at dardo dot pl | Date: | Sun, 04 Sep 2005 18:24:36 +0000 |
| Subject: | note 56485 added to language.oop5 | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-94726@lists.php.net to get a copy of this message | ||
In regards to hans at lintoo dot dk
When you need give different type of param(s):
<?php
class ABC{
public function __construct($param=null) {
switch(gettype($param)){
case 'integer':
// do something with integer
// example run $this->start_with_string($param);
break;
case 'string':
// do something with string
// example run $this->start_with_int($param);
break;
default:
throw new Exception("Error: __construct called with wrong type (only string *OR*
int)");
}
}
}
$a = new ABC('text'); // works with string field
$b = new ABC(4); // works with intereg field
Arek Macak
?>
----
Manual Page -- http://www.php.net/manual/en/language.oop5.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56485
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56485&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56485&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56485&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56485&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56485&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56485&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56485&report=yes
Search -- http://master.php.net/manage/user-notes.php