Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 721939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:55:52+00:00 2026-05-14T05:55:52+00:00

i have a class that extends another. when i iterate the current object i

  • 0

i have a class that extends another.

when i iterate the current object i get all properties, even those from the superclass.

i only want to iterate through the current object. how could i do that?

foreach($this as $key => $value) {
    echo $key . ': ' . $value;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T05:55:53+00:00Added an answer on May 14, 2026 at 5:55 am

    Very interesting question.

    I will highly recommend to read the examples here – http://dsl093-056-122.blt1.dsl.speakeasy.net/edu/oreilly/Oreilly_Web_Programming_bookshelf/webprog/php/ch06_05.htm they will give you greater insight about Introspection. The reference about those methods used is here – http://www.php.net/manual/en/ref.classobj.php


    Here is the function with a test case. It will work only in PHP 5+ as it uses Reflection which was not available before that. You can read more about Reflection here – http://www.php.net/manual/en/class.reflectionclass.php

    <?php
    
    echo '<pre>';
    
    class A {
        public $pub_a = 'public a';
        private $priv_a = 'private a';
    }
    
    class B extends A {
        public $pub_b = 'public b';
        private $priv_b = 'private b';
    }
    
    $b = new B();
    
    print_r(getChildrenProperties($b));
    
    function getChildrenProperties($object) {
        $reflection = new ReflectionClass(get_class($object));
        $properties = array();
    
        foreach ($reflection->getProperties() as $k=>$v) {
            if ($v->class == get_class($object)) {
                $properties[] = $v;
            }
        }
    
        return $properties;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that I want to use to store properties for another
I have class that extends another class. class TWITTER_FOLLOWERS extends TWITTER_BOT in TWITTER_FOLLOWERS i
If I have a base class such that public abstract class XMLSubscription <T extends
I have a few classes such that: public class XMLStatusMessage extends XMLMessage {} public
I have class method that returns a list of employees that I can iterate
I have a class that creates several IDisposable objects, all of these objects are
I have a class that extends a class that I need to overide, but
I have a class that extends Zend_Db_Table lets call it 'Users' that uses the
I have a class that extends Composite and contains a DisclosurePanel at the top-level
In a Silverlight 4 project I have a class that extends Canvas: public class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.