Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

Types.php

Go to the documentation of this file.
00001 <?php 00002 /* vim: set expandtab tabstop=4 shiftwidth=4: */ 00003 // 00004 // Copyright (c) 2003 Laurent Bedubourg 00005 // 00006 // This library is free software; you can redistribute it and/or 00007 // modify it under the terms of the GNU Lesser General Public 00008 // License as published by the Free Software Foundation; either 00009 // version 2.1 of the License, or (at your option) any later version. 00010 // 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 // Lesser General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU Lesser General Public 00017 // License along with this library; if not, write to the Free Software 00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 // 00020 // Authors: Laurent Bedubourg <laurent.bedubourg@free.fr> 00021 // 00022 00029 class Types 00030 { 00037 function toString(&$var) 00038 { 00039 if (is_object($var)) { 00040 return Types::_objToString($var); 00041 } elseif (is_array($var)) { 00042 if (array_key_exists(0, $var) || count($var) == 0) { 00043 return Types::_arrayToString($var); 00044 } else { 00045 return Types::_hashToString($var); 00046 } 00047 } elseif (is_resource($var)) { 00048 return '#'.gettype($var).'#'; 00049 } 00050 return $var; 00051 } 00052 00060 function _objToString(&$var) 00061 { 00062 if (method_exists($var, "toString")) { 00063 return $var->toString(); 00064 } else { 00065 return '<' . get_class($var) . ' instance>'; 00066 } 00067 } 00068 00075 function _arrayToString(&$var) 00076 { 00077 $values = array(); 00078 foreach ($var as $val) { 00079 $values[] = Types::toString($val); 00080 } 00081 return '[' . join(', ', $values) . ']'; 00082 } 00083 00090 function _hashToString(&$var) 00091 { 00092 $values = array(); 00093 foreach ($var as $key=>$val) { 00094 $values[] = '\''. $key . '\': ' . Types::toString($val); 00095 } 00096 return '{' . join(', ', $values) . '}'; 00097 } 00098 } 00099 00100 ?>

Generated on Tue Jun 29 23:40:07 2004 for Mediawiki by doxygen 1.3.7