Results 1 to 3 of 3

Thread: Array of type class

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Array of type class

    I'm making a class (just basics) and I need help on returning an array of my object. Something like this
    VB Code:
    1. <?php
    2. class comment{
    3.     function select_all(){
    4.         // I should return all comments from the database.
    5.     }
    6. }
    7. ?>
    Something like this in java.
    VB Code:
    1. import java.util.*;
    2. public class comment{
    3.     public List<comment> select_all(){
    4.         List<comment> list=new ArrayList<comment>();
    5.         return list;
    6.     }
    7. }
    Hope I don't make non sense post.

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Array of type class

    Is this in PHP 4, if so you should use references:
    PHP Code:
    <?php
    //PHP 4
    class comment{
        function 
    select_all(){
            
            
    // I should return all comments from the database.
            
    $ret = Array(); // create blank array

            // code here o get comments
            
            
    foreach ($comments as $comment) {
                
    $ret[] = & new Comment($comment); // use the & operator to make it a reference
            
    }

            return 
    $ret;        

        }
    }
    ?>
    In PHP 5 references are automatic:
    PHP Code:
    <?php
    //PHP 5
    class comment{
        public function 
    select_all(){
            
            
    // I should return all comments from the database.
            
    $ret = Array(); // create blank array

            // code here to get comments
            
            
    foreach ($comments as $comment) {
                
    $ret[] = new Comment($comment); // no reference needed
            
    }

            return 
    $ret;        

        }
    }
    ?>
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Re: Array of type class

    Thanks, I'll try that one and post if I have some question(s). Thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width