note 17465 deleted from language.oop by jimw
| From: | jimw@php.net | Date: | Thu, 20 Dec 2001 23:18:40 +0000 |
| Subject: | note 17465 deleted from language.oop by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-23552@lists.php.net to get a copy of this message | ||
If you want to use classes just as namespaces (just like in C or C++), make '::' - calls.
It doesn't create an object, but is a 'clean' method of handling functions. You may
even overwrite a function of a standard library.
Example:
<?
if(!defined("_INCLUDE_NAMESPACE_TEXTFUNCTIONS_"))
{
define("_INCLUDE_NAMESPACE_TEXTFUNCTIONS_",TRUE);
/***************************************
Namespace for string functions
!!! ATTENTION !!!
this is a namespace and not a class,
so please don't instance it, even if it's
possible.
I packed all the functions in a class, because
PHP in the actual version don't offer the namespace option
// (c) 06.11.01 Alexander Filatow
***************************************/
class NTextFunctions
{
// replaces the String::Substr Function by my own
// by adding "..." in the end if necessarily
function Substr($str, $length)
{
$ret = substr($str, 0, $length);
if (strlen($str) > $length) $ret .= "...";
return $ret;
}
} // end of class
} // end of define
else die ("ERROR INCLUSION");
?>
Usage at a web page:
include ("class.textfunctions.php");
echo NTextFunctions::Substr("abcdefg", 3);