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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:50:34+00:00 2026-05-31T21:50:34+00:00

I have this strange error, When I call $element_attrs = $element -> attributes(); I

  • 0

I have this strange error,

When I call $element_attrs = $element -> attributes(); I get a notice saying the attribute method does not exist:

Call to undefined method stdClass::attributes();

now when I call die( get_class( $element ) ); Right before the attributes() call, php returns Select_Element which is correct!

Form_Element contains the attribute(); method.

I am positive Select_Element extends Form_Element and both files are included indefinately.

HOWEVER

if I call:

if ( method_exists($element, "attributes") ) {
    $element_attrs = $element -> attributes();
}

IT WORKS! method_exists returns true, and attributes() is called! but when I remove the if command, I get the error notice again…

What the hell is going on!

CODE

interface Element{
    public function __construct( $element );
    public function parse();
}

class Form_Element implements Element{

    protected $element;

    public function __construct($json_element){
        $this -> element = $json_element;
    }

    public function parse(){
        // Removed parsing code, unrelated
    }

    ... removed unrelated methods ...

    public function attributes( $key = null, $value = null ){
        if ( is_null( $key ) ){
            return $this -> element -> attributes;
        }
        else{
            $this -> element -> attributes -> $key = $value;
        }
    }
}

class Select_Element extends Form_Element implements Element{

    public function __construct( $element ) {
        parent::__construct( $element );
    }

    public function parse(){
        // Removed parsing code, unrelated
    }
}

and this is where the code is called in a Form class :

// note: $this -> elements is an array of Form_Element objects

public function edit_form($name_of_element, $name_of_value, $value){
    foreach ( $this -> elements as $element ){
        if ( method_exists($element, "attributes") ) {
            $element_attrs = $element -> attributes();
        }
        if ( $element_attrs -> name == $name_of_element ){
            switch ( $name_of_value ){
                case "selected" :
                    $element -> selected( $value );
                    break;
                case "options" :
                    $element -> options( $value );
                    break;
                case "value" :
                    $element -> value( $value );
                    break;
                // add more support as needed
            }
        }
    }
}

Does anybody know why PHP thinks attributes(); doesnt exist? Even though method_exists($element, "attributes"); returns true ?

  • 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-31T21:50:35+00:00Added an answer on May 31, 2026 at 9:50 pm

    You say you are in a loop with this.

    Most likely, the code you show is called twice, once with $element being the desired object, and once not – when you use method_exists(), the code walks past that point, and if you don’t use it, it crashes.

    When you use die(), the loop terminates at the first element. But that is not necessarily the element that is causing the problem.

    The error message

    Call to undefined method stdClass::attributes();
    

    supports this: note the stdClass where it should read Form_Element.

    So you need to find out why $element is not always the object you want it to be.

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

Sidebar

Related Questions

it is very strange, because this error doesn't happen all the time... I have
I have this strange call stack and I am stumped to understand why. It
While refactoring some code, I came across this strange compile error: The constructor call
I have this strange error in one of my rails 2.3.2 application. NoMethodError in
I have strange error, when I try to import numpy: Traceback (most recent call
I have cornered this error down to a redirect action call by DotNetOpenAuth( http://www.dotnetopenauth.net/
I have this strange issue with my web app. You see, I'm using jQuery
This is a strange one... In a windows forms app (VB.NET/VS 2005) I have
Why this two functions have the strange behaviour of when I click on thead,
This a bit of strange one.... We have an internal web app that runs

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.