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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:01:49+00:00 2026-05-27T01:01:49+00:00

I can’t seem to get this right.. It seems I keep creating a new

  • 0

I can’t seem to get this right.. It seems I keep creating a new stdClass when I’m tryng to add to what should be one for the scope.

    class d_elem {
        private $el;
        function __constructor($p) {
            $el = new stdClass;
        }
        private static function ele_base($p) {
            print('ele_base<br/>');
            d_elem::ele_base_attr($p);
        }
        private static function ele_base_attr($p) {
            print('ele_base_attr<br/>');
            isset($p['id']) ? $el->id = '' . $p['id'] . '' : '';
            print_r($p);print('<br/>');
            print_r($el);print('<br/>'); //<< should have added the id but created a new one????
        }
        public static function ele_a($p) {
            d_elem::ele_base($p);
            isset($p['href']) ? $el->href = '' . $p['href'] . '' : '';
            isset($p['TEXT']) ? $el->TEXT = '' . $p['TEXT'] . '' : '';
            print_r($p);print('<br/>');
            print_r($el);print('<br/>');//<< should have added the id but only has the href and TEXT when all 3 should be there
            //skip the retrun
        }
    }

    echo d_elem::ele_a(array('href'=>"#",'TEXT'=>'test','id'=>'test'));

Any one have an idea?

thank you -Jeremy

[EDIT]————————————–
per the suggestion above

    class d_elem{
        public static $el;
        private static function init(){ 
            self::$el = new stdClass; 
        } 
        private static function ele_base($p) {
            print('ele_base<br/>');
            self::ele_base_attr($p);
        }
        private static function ele_base_attr($p) {
            print('ele_base_attr<br/>');
            isset($p['id']) ? $el->id = '' . $p['id'] . '' : '';
            print_r($el);print('<br/>'); //<< should have added the id but created a new one????
        }
        public static function ele_a($p) {
            self::init();
            self::ele_base($p);
            isset($p['href']) ? $el->href = '' . $p['href'] . '' : '';
            isset($p['TEXT']) ? $el->TEXT = '' . $p['TEXT'] . '' : '';
            print_r($el);print('<br/>');
            //skip the retrun
        }
    }

    d_elem::ele_a(array('href'=>"#",'TEXT'=>'test','id'=>'test'));

Still produces the same output of

ele_base

ele_base_attr

stdClass Object ( [id] => test )

stdClass Object ( [href] => # [TEXT] => test )

.

and want

stdClass Object ( [id] => test [href] => # [TEXT] => test )

tk -J

[END SOLUTION AS OF YET]

        class d_elem {
            private static $el;  /// fill this as we run from function to function
            private static function init(){ // start off but creating the object
                self::$el = new stdClass; 
            } 
            private static function ele_base($p) {
                self::ele_base_attr($p);// here we fill base on some condition.. simple test first
            }
            private static function ele_base_attr($p) {
                isset($p['id']) ? self::$el->id = ' id="' . $p['id'] . '" ' : '';  // this should be pushed to the class level object
            }
            public static function ele_a($p) {
                $p=!is_array($p)?get_object_vars ($p):$p; // make sure that if p is an object we trun it to an array
                self::init();// set the class object
                self::ele_base($p);// make first add to class object
                isset($p['href']) ? self::$el->href = ' href="' . $p['href'] . '" ' : ''; make second add to the class object
                foreach (self::$el as $key => $value) {
                    $ele .= $value; // spit the values back out to return from the class object
                }
                $ele .= $p['TEXT'] ; // test something to return at this level 
                return $ele // return all the properties in this case a string of them
            }
        }

        echo d_elem::ele_a(array('href'=>"#",'TEXT'=>'test','id'=>'test')); // call for the output
  • 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-27T01:01:50+00:00Added an answer on May 27, 2026 at 1:01 am

    I can’t fix everything, but a few things to note:

    __constructor() never gets called, because the class never gets instantiated, only called statically (and should be called __construct()).

    There’s no need to echo d_elem::elem_a() because nothing is returned.

    If you want to use the function as static functions, the $el variable also needs to be static, and referred to as self::$el. Similarly, when calling static functions inside the object you should call them as self::ele_base_attr() etc.


    EDIT: You could turn the __construct into a static function, ie:

    private static function init()
    {
        self::$el = new stdClass;
    }
    

    Then call self::init() before doing anything else in d_elem::elem_a().


    EDIT: This achieves the same thing:

    class d_elem {
        public static $el;
    
        public static function ele_a($p) {
            self::$e = new stdClass;
    
            if(isset($p['href'])) $el->href = $p['href'];
            if(isset($p['TEXT'])) $el->TEXT = $p['TEXT'];
            if(isset($p['id'])) $el->id = $p['id'];
    
            print_r(self::$el);
        }
    }
    
    d_elem::ele_a(array('href'=>"#",'TEXT'=>'test','id'=>'test'));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anybody help me? What should be the datatype for this type -07:00:00 of
Can't seem to get the Back Button to appear in a UINavigationController flow. I
can any one tell me how can change this java code into objective c.is
can you recommend some good ASP.NET tutorials or a good book? Should I jump
Can I get a 'when to use' for these and others? <% %> <%#
Can you suggest some good MVC framework for perl -- one I am aware
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Can I run this in a Windows command prompt like I can run it
can someone explain why the compiler accepts only this code template<typename L, size_t offset,
Can't figure out how to do this in a pretty way : I have

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.