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 7526499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:50:53+00:00 2026-05-30T03:50:53+00:00

Considering this basic code snippet: <? class mcClassington { var $mcProperty=’default’; function mcDoSomething() {

  • 0

Considering this basic code snippet:

<?
  class mcClassington
  {
        var $mcProperty='default';

        function mcDoSomething()
        {
               if($this->mcProperty == (/* new type of same class */)->mcProperty)
               {
                       sameBusiness();
               }
               else
               {
                       sortIt($this->mcProprety);
               }
        }
 }

Not sure how I can ask for a new object of whichever type the $this instance is.

I’m trying to write this function for a base class but let classes which extend from it check against their own default values. All I could think of was super-ghetto using switch(get_class($this)) but that would completely destroy the dynamic goal of the code I’m working on.

EDIT: So,.. I can’t actually post the complete real code. The best I can provide is a static example of usage posted below.

class displayObject //implements attachable
{
    public $layer = null;
    public $xPos = Array(
                        'left'=>null, 
                        'width'=>null,
                        'margin-left'=>null,
                        'margin-right'=>null,
                        'padding-left'=>null,
                        'padding-right'=>null
                    );
    public $yPos = Array(
                        'top'=>null,
                        'height'=>null,
                        'margin-top'=>null,
                        'margin-bottom'=>null,
                        'padding-top'=>null,
                        'padding-bottom'=>null
                    );
}


class Button extends displayObject
{
    public $link, $image, $backing;
    public $xPos = Array(
                        'left'=>null, 
                        'width'=>'120px',
                        'margin-left'=>'8px',
                        'margin-right'=>'8px',
                        'padding-left'=>null,
                        'padding-right'=>null
                    );
    public $yPos = Array(
                        'top'=>null,
                        'height'=>'108px',
                        'margin-top'=>'4px',
                        'margin-bottom'=>'4px',
                        'padding-top'=>null,
                        'padding-bottom'=>null
                    );
}

And then, in other files people might use the class like so:

$navBar = Array();  // Will hold basic Button Objects

$specialtyButton = new Button();
$specialtyButton->$xPos['width'] = '220px';
$specialtyButton->$yPos['height'] = '220px';
/*  and so on...    */

The function I’m writing must be called from within the base class displayObject in the format myFunction($this); What I’m trying to solve is sorting the pseudo-styles into different places based on whether or not they are the same as their default values.

For instance, $specialtyButton would be sorted specially because it’s width and height differed from Button’s default values but the Buttons inside $navBar would be overlooked because nothing was set explicitly.

  • 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-30T03:50:54+00:00Added an answer on May 30, 2026 at 3:50 am

    You can simply:

    $myClassName = get_class($this);
    $newObj = new $myClassName;
    if ($this->mcProperty == $newObj->mcProperty) {
      // ...
    

    …but I wouldn’t. I would say it would be more sensible to hold the default values in a private property, so no-one can modify them, and compare against them instead. Creating new instances just to check if values are default seems like a horrible thing to do to me…

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

Sidebar

Related Questions

Considering this code, can I be absolutely sure that the finally block always executes,
I have this small code library that I'm considering releasing into Open Source. I
I apologize if this code looks a bit like a mess (considering the length);
Considering that this is a very basic task, I could not think of an
I'm new to Rails so this is really basic and I'm sure I'm missing
considering this example: public static void main(final String[] args) { final List<String> myList =
Considering this xml document: DECLARE @X XML (DOCUMENT search.SearchParameters) = '<parameters xmlns=http://www.educations.com/Search/Parameters.xsd xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance> <parameter
Considering this question of SO, where whole C# in-memory compiler is being called. When
I'm not considering this - I'm comfortable with C# and VB, but an expert
I'm considering using this jquery utility as a possible solution, but I want to

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.