note 75515 added to language.oop5
| From: | openspecies at osu1 dot php dot net | Date: | Sun, 03 Jun 2007 16:01:06 +0000 |
| Subject: | note 75515 added to language.oop5 | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-127163@lists.php.net to get a copy of this message | ||
<?PHP
define('__OS_SEP__',DIRECTORY_SEPARATOR);
if(!defined('__LOG_FILE__'))
define('__LOG_FILE__',
__OS_SEP__.'tmp'.__OS_SEP__.'php.log.txt'
);
/**
* INTERFACE __ExitOnError
*/
interface __ExitOnError
{
public function __exit();
};
/**
* abstract class _Exception extends Exception
*/
abstract class _Exception extends Exception
{
abstract public function message();
abstract public function trace();
abstract public function show();
};
/**
* class CoreException extends _Exception implements __ExitOnError
* Application Core Exceptions Service
*/
class CoreException extends _Exception implements __ExitOnError
{
private $log_string = NULL;
/**
* public function message($show = FALSE)
*/
public function message($show = FALSE)
{
$this->log_string = sprintf("+ %s::%s (%s) \n", get_class($this),
self::getMessage(), date('d/m/Y H:i:s'));
if($show)
$this->show();
return $this->log_string;
}
/**
* public function trace($show = FALSE)
* @return string
*/
public function trace($show = FALSE)
{
$buff = sprintf("+ %s::%s (%s) \n", get_class($this), self::getMessage(),
date('d/m/Y H:i:s'));
$trace = self::getTrace();
$entry = array('file','line','function','args');
foreach($trace as $v) :
$tab.= "\t";
$buff.= $tab."+ Exception in\n";
foreach($entry as $e) :
$i = 0 ;
if(is_array($v[$e])) :
foreach($v[$e] as $k) :
$buff.= sprintf("%s+---- function %s[%d] = %s\n", $tab, $e, $i++,
(is_object($k)) ? serialize($k) : $k);
endforeach;
else :
$buff.= sprintf("%s+---- %s %s\n", $tab, $e, (is_object($v[$e])) ?
serialize($v[$e]) : $v[$e]);
endif;
endforeach;
endforeach;
$this->log_string = $buff;
unset($buff,$trace);
if(__DEBUG__)
@error_log($this->log_string, 3, __LOG_FILE__);
if($show)
$this->show();
return $this->log_string;
}
/**
* public function show()
*/
public function show()
{
echo $this->log_string;
}
/**
* public function isExternError($o)
* @return bool
*/
public function isExternError($o)
{
if (PEAR::isError($o)) :
return TRUE;
endif;
return FALSE;
}
public function __exit($flag = 0)
{
exit($flag);
}
function __destruct()
{
unset($this->log_string);
}
};
/**
* final class enum_exception extends CoreException
*/
final class enum_exception extends CoreException {};
/**
* final class enum
*/
final class enum
{
private $__this = array();
final function __construct()
{
$args = func_get_args();
$i = 0;
do{
try {
if(preg_match('/^[a-zA-Z_]+$/',$args[$i])) :
if(!defined($args[$i])):
define($args[$i],$i);
$this->__this[$args[$i]] = $i;
endif;
else:
throw new enum_exception('Data type error : "'.$args[$i].'"
received; expected ^[a-zA-Z_]+$ string');
endif;
} catch(enum_exception $ex){$ex->trace(TRUE);$ex->__exit();}
} while(count($args) > ++$i);
}
public function __get($k)
{
return $this->__this[$k];
}
};
$days = new enum(
"Saturday",
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday"
);
$today = $days->Thursday;
echo $today."\n";
new enum(
'__MONDAY__',
'__TUESDAY__',
'__WEDNESDAY__',
'__THURSDAY__',
'__FRIDAY__',
'__SATURDAY__',
'__SUNDAY__'
);
$day_index = 1; /* {0,6} */
switch($day_index) :
case __MONDAY__: echo "Monday \n"; break;
case __TUESDAY__: echo "Tuesday \n"; break;
case __WEDNESDAY__: echo "Wednesday \n"; break;
case __THURSDAY: echo "Thursday \n"; break;
case __FRIDAY__: echo "Friday \n"; break;
case __SATURDAY__: echo "Saturday \n"; break;
case __SUNDAY__: echo "Sunday \n"; break;
endswitch;
new enum(
" !MAL FORMATTED**"
);
?>
----
Server IP: 69.147.83.197
Probable Submitter: 81.57.229.223
----
Manual Page -- http://www.php.net/manual/en/language.oop5.php
Edit -- https://master.php.net/note/edit/75515
Del: integrated -- https://master.php.net/note/delete/75515/integrated
Del: useless -- https://master.php.net/note/delete/75515/useless
Del: bad code -- https://master.php.net/note/delete/75515/bad+code
Del: spam -- https://master.php.net/note/delete/75515/spam
Del: non-english -- https://master.php.net/note/delete/75515/non-english
Del: in docs -- https://master.php.net/note/delete/75515/in+docs
Del: other reasons-- https://master.php.net/note/delete/75515
Reject -- https://master.php.net/note/reject/75515
Search -- https://master.php.net/manage/user-notes.php