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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:33:51+00:00 2026-06-15T10:33:51+00:00

So I wrote a basic class which I have extended to create html element.

  • 0

So I wrote a basic class which I have extended to create html element. Based on Zend – HOWEVER not exactly. No this is not a question about or in relation to zend

class AisisCore_Form_Elements_Input extends AisisCore_Form_Element {

    protected $_html = '';

    public function init(){

        foreach($this->_options as $options){
            $this->_html .= '<input type="text" ';

            if(isset($options['id'])){
                $this->_html .= 'id="'.$options['id'].'" ';
            }

            if(isset($options['class'])){
                $this->_html .= 'class="'.$options['class'].'" ';
            }

            if(isset($options['attributes'])){
                foreach($options['attributes'] as $attrib){
                    $this->_html .= $attrib;
                }
            }

            $this->_html .= $this->_disabled;
            $this->_html .= ' />';

            return  $this->_html;
        }
    }
}

so this class extends my element class which consists of a constructor that takes in an array of options, a basic element is set up as such:

$array_attrib = array(
    'attributes' => array(
        'placeholder' => 'Test'
    )
);

$element = new AisisCore_Form_Elements_Input($array_attrib);
echo $element;

So what’s the problem?

echoing the $element object gives me an error saying it cant convert the object to a string, thus when I var_dump it I get this back:

object(AisisCore_Form_Elements_Input)#21 (3) {
  ["_html":protected]=>
  string(22) "<input type="text"  />"
  ["_options":protected]=>
  array(1) {
    ["attributes"]=>
    array(1) {
      ["placeholder"]=>
      string(4) "Test"
    }
  }
  ["_disabled":protected]=>
  NULL
}

Can some one explain what’s going on? Last I checked I was echoing out a string not an object. How did I manage to create an object?

If you need to see the AisisCore_Form_Element class I will post it how ever all this class is a base class you extend to create the element. the only thing it takes is an array of options.

  • 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-15T10:33:52+00:00Added an answer on June 15, 2026 at 10:33 am

    Looks like your constructor was trying to return a value (in the middle of the for loop as well), when you probably wanted to something like this….

    class AisisCore_Form_Elements_Input extends AisisCore_Form_Element {
    
        protected $_html = '';
    
        public function init(){
    
            foreach($this->_options as $options){
                $this->_html .= '<input type="text" ';
    
                if(isset($options['id'])){
                    $this->_html .= 'id="'.$options['id'].'" ';
                }
    
                if(isset($options['class'])){
                    $this->_html .= 'class="'.$options['class'].'" ';
                }
    
                if(isset($options['attributes'])){
                    foreach($options['attributes'] as $attrib){
                        $this->_html .= $attrib;
                    }
                }
    
                $this->_html .= $this->_disabled;
                $this->_html .= ' />';
    
                // Constructors Don't Return Values - this is wrong
                //return  $this->_html;
            }
        }
    
        // provide a getter for the HTML
        public function getHtml()
        {
             return $this->_html;
        }
    }
    

    Now your example can be updated to look like this…

    $element = new AisisCore_Form_Elements_Input($array_attrib);
    echo $element->getHtml();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have wrote a basic web service using .net which I intend to use
i have rather very basic question. I have one GUI class and another which
I wrote a basic Hippity Hop program in C, Python, and OCaml. Granted, this
I'm trying to write a basic script which creates a UI. I have reduced
I have a templatized container class in C++ which is similar to a std::map
I have a small 3D vector class in C# 3.0 based on struct that
Simple question. A friend of mind wrote code similar to this one (which is
It seems interesting, that nobody asked this before. I have some basic-questions about the
I recently wrote a node-based stack class, per instructions (specs in the comments before
I have a baseDAO which contains methods for basic CRUD operations. And for each

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.