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

  • SEARCH
  • Home
  • 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 9224317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:17:23+00:00 2026-06-18T04:17:23+00:00

I want to create the setProperties() method inside of the Abstract class which looks

  • 0

I want to create the setProperties() method inside of the Abstract class which looks like this:

public function setProperties($array = null) {

        if (!empty($array)) {
            foreach($array as $key => $value) {
                if (property_exists($this, $key)) {
                    $this->{$key} = $value;
                }
            }
        }

    }

What I’m not quite sure about is whether I’ll be able to use it in the classes that inherit from this Abstract class to set the inherited properties as well as the child class specific.

I’m not sure if I should use any other keyword then $this in the property_exists() function – perhaps there’s a way by using late static bindings (static::) keyword?

  • 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-06-18T04:17:24+00:00Added an answer on June 18, 2026 at 4:17 am

    Your code should basically work. Imagine this simple example what outputs two times true:

    abstract class A {
    
        protected $var1;
    
        public function exists1() {
            var_dump(property_exists($this, 'var2'));
        }
    
    }
    
    class B extends A {
    
        protected $var2;
    
        public function exists2() {
            var_dump(property_exists($this, 'var1'));
        }
    }
    
    
    $o = new B();
    
    $o->exists1();
    $o->exists2();
    

    As you can see, property_exists() works when the child class is accessing a member from the parent class and vise versa when the parent class is trying to access a member of the child.

    That’s one of the basic concepts of abstraction. What you are trying to do is absolutely ok. If you get an error anyway, it must be a little overseen detail

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want create subdomains like this: domain.com/type/city An examples: domain.com/restaurants/new_york domain.com/hotels/new_york domain.com/restaurants/chicago I have
i want create jqGrid like this I could divid body jqGrid i write this
I want to create an abstract base class for all paramter-type classes to inherit
I want create wordpress website into which I want create user management... That means
i want create Dynamic Slideshow in Jquery i'm Write this code var ctx =
I want create module which update list of usb devices automatically (not only mass
Lets say I have this class class Child { public string FirstName { get;
Say I have some method like so: public void Method<T>(Func<T> func) { ... }
I want to create a list of BrushInfo which has properties of a brush
I would like to create a class with properties that have subproperties... In other

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.