An Simple Collection Class

简介:
 
Construct an Collection:
/** 
* @copyright    2009-1-16 
* @author Tom Zhou     MSN:danni-505@hotmail.com 
* @Info: Use ArrayObject to build an super simple collection, 
*         it can be used to store various of data, such as DB connection,Object etc.    
*    
* @access anything 
* @return data of corresponding opposite    
*/
 

class MySimpleCollection  extends ArrayObject{ 
   /** 
    * if identity private variable, in construct you should call parent construct and set the 
    * instance to this private variable. 
    * antoher way is never override this construct method 
    */
 
//  private    $collection; 
//  function __construct(){ 
//    parent::__construct(); 
//    $this->collection=$this; 
//  } 
     
  function addObject($_index,$_object){ 
    $ this->offsetSet($_index,$_object); 
  } 
    
  function getObject($_index){ 
     return $ this->offsetGet($_index); 
  } 
    
  function delObject($_index){ 
    $ this->offsetUnset($_index); 
  } 
    
  function printCollection(){ 
    echo  "<pre>"
    print_r($ this); 
    echo  "</pre>"
  } 
}
 
Store some data
 
//#get some object 
    $user= new userObject();      //#general object 
    $dao= new userDao();              //#DB object 
     //#put into collection 
    $colletionInstance= new MySimpleCollection(); 
    $colletionInstance->addObject(1,$user); 
    $colletionInstance->addObject(2,$dao->dbObjInstance); 
    $colletionInstance->addObject(3,$_SESSION[ "URL_FROM"]); 
    $colletionInstance->addObject(4,serialize( "daniel")); 
    $colletionInstance->addObject(5,unserialize(serialize( "daniel")));     
    $colletionInstance->addObject(6,array(0=> "string",1=>array( "name"=> "daniel"), "last name"=> "zhou")); 
    $colletionInstance->addObject(7,array(0=> "daniel")); 
    $colletionInstance->addObject(8,0.2356); 
    $colletionInstance->addObject(9, "daniel");     
     //#have a look 
    $colletionInstance->printCollection();     
    $iterater=$colletionInstance->getIterator(); 
     while ($iterater->valid()) { 
            echo $iterater->current(). "<br>"
            echo $iterater->key(). "<BR>"
            $iterater->next(); 
    }
 
then take a look
MySimpleCollection Object 

        [1] => user Object 
                ( 
                        [no] => 1 
                ) 

        [2] => dbObjMySQL Object 
                ( 
                        [db_host] => 192.168.1.166 
                        [db_name] => LOAN163 
                        [user_name] => root 
                        [pass_code] => 2008like18 
                        [db_connect] => Resource id #22 
                        [db_rec] =>    
                        [ErrMsg] =>    
                        [PHPErrCd] =>    
                        [PHPErrMsg] =>    
                        [PHPSQL] =>    
                        [tran_flg] =>    
                        [new_link] =>    
                ) 

        [3] => /backyard/?Command=Admin_Login 
        [4] => s:6: "daniel"
        [5] => daniel 
        [6] => Array 
                ( 
                        [0] => string 
                        [1] => Array 
                                ( 
                                        [name] => daniel 
                                ) 

                        [last name] => zhou 
                ) 

        [7] => Array 
                ( 
                        [0] => daniel 
                ) 

        [8] => 0.2356 
        [9] => daniel 


Object id #6 

Object id #10 

/backyard/?Command=Admin_Login 

s:6: "daniel"

daniel 

Array 

Array 

0.2356 

daniel 
9


    本文转自danni505 51CTO博客,原文链接:http://blog.51cto.com/danni505/131334,如需转载请自行联系原作者



相关文章
|
3月前
|
Java 数据库
成功解决: 加上 @Transient 仍然报 Unknown column ‘goods_list‘ in ‘field list‘
这篇文章讨论了在SpringBoot结合MyBatis-Plus框架中,当实体类中包含另一个实体类的集合,而这个集合字段在数据库中不存在时,如何避免由此引发的错误。文章提供了两种解决方法:一是使用`@TableField(exist = false)`注解明确指定该字段在数据库中不存在;二是使用`transient`关键字,但要注意`transient`关键字在Java中默认就是被忽略的,不需要加`@Transient`注解。文章最后展示了问题解决的效果。
Unknown custom element: <add-employee> - did you register the component correctly? For red cursive c
原因: 1.组件名没写对(导入和注册不对应) 2.components少写了个s 3.组件命名最好是驼峰命名 4.导入时语法错误 5.代码中有两个components,后一个的值把前一个覆盖了 6.组件直接循环套用了
|
Java 关系型数据库 MySQL
15. 成功解决:java: Can't generate mapping method with primitive return type.
今天启动 SpringBoot 项目时,报了如下错误:`java: Can't generate mapping method with primitive return type.`
1011 0
Could not resolve element type of Iterable type xxxxx.RequestParam java.util.List<?>. Not declared?
Could not resolve element type of Iterable type xxxxx.RequestParam java.util.List<?>. Not declared?
Could not resolve element type of Iterable type xxxxx.RequestParam java.util.List<?>. Not declared?
【Junit 报错】Test class should have exactly one public zero-argument constructor和Test class can only have one constructor
错误1: 1 java.lang.Exception: Test class should have exactly one public zero-argument constructor 2 at org.
6154 0
Object C学习笔记18-SEL,@ selector,Class,@class
  本章是对上一章的一点补充,所以比较简单点。     一. SEL 类型     在上一篇介绍了几个方法,都只是介绍了其使用方式但是没有具体介绍参数: - (id)performSelector:(SEL)aSelector; - (id)performSelector:(SEL)a...
959 0
下一篇
无影云桌面