www.webdeveloper.com
Results 1 to 4 of 4

Thread: [RESOLVED] How to get all variables in an object

  1. #1
    Join Date
    Oct 2007
    Posts
    366

    resolved [RESOLVED] How to get all variables in an object

    Is there an equivilent function to foreach that will access all the variables and there values from a class object?

    Code:
    <?pseudocode:
    
    $da= new calenderDate;
    
    foreach ($da as ...){do whatever}
    
    /pseudocode?>
    Just beginning to teach myself OOP and wanted a quick way to test a class.

  2. #2
    Join Date
    Oct 2008
    Posts
    150
    Try
    PHP Code:
    print_r((array) $obj); 
    or check out get_object_vars().

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,924
    Take a look at the Object Iteration manual page.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  4. #4
    Join Date
    Oct 2007
    Posts
    366
    NogDog and Sodbuster,
    Thank you very much for pointing me in the right direction. I see there are also get_class_methods() - Gets the class methods' names
    get_class_vars() - Get the default properties of the class
    That will help me when I am dealing with another person's code to make it easier to deal with.

    Thank you, thank you, thank you.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles