Jump to content

Unable to set values of attributes vis constructor

- - - - -

  • Please log in to reply
3 replies to this topic

#1
thatsme

thatsme

    Programmer

  • Members
  • PipPipPipPip
  • 176 posts
Hi. I am tying to pass names of header and footer files to class's constructor with such line: $site = new site("header.php", "footer.php"); Here is constructor:
public function _construct($header, $footer){
            $this->header = $header;
            $this->footer = $footer;
}
The problem is that i get error of undefined values when i use header and footer in include function
public function render(){
            include $this->header;
            $this->page->render();
            include $this->footer;
}
I would appreciate any help

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
Hello,

Magic functions have two underscores before each function, this better helps to separate normal functions from magic functions:

php.net said:

PHP reserves all function names starting with __ as magical. It is recommended that you do not use function names with __ in PHP unless you want some documented magic functionality.

public function __construct($header, $footer) {

You can read more about them here:
PHP: Magic Methods - Manual
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#3
thatsme

thatsme

    Programmer

  • Members
  • PipPipPipPip
  • 176 posts
thanks, that helped

#4
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200

thatsme said:

thanks, that helped
Of course, you are always welcome.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users