0

I am getting this warning in PHP 7.2 that wasn't showing up in 5.6.

Warning: Use of undefined constant object - assumed 'object'

Here's what my code looks like...

CLASS WPA_PAGE {

  VAR $obj_template = object;

  function build_content() {
     global $app;

     $this->obj_template = new wpa_custom_template();   <---Warning occurs Here.
  }
}

** Note that I have stripped out a lot of code for purposes of this post.

As you can see, I have declared $this->obj_template in the beginning of the class. I have a lot of similar code to this that doesn't seem to be generating any sort of error.

Is there something wrong with my syntax here or do you think something that is unsetting the variable/object before I am instantiating it?

can anyone help?

3
  • 1
    Are you sure the error isn't in this line: VAR $obj_template = object;? This looks a lot like PHP 4. Time to update your code. Commented Jan 21, 2019 at 5:34
  • That is certainly possible. The code is pretty old. What is the correct way to declare an variable of type object? Commented Jan 21, 2019 at 6:06
  • Object should be a keyword so there is your error. I would define it as null. Commented Jan 21, 2019 at 6:18

1 Answer 1

1

The problem is with line VAR $obj_template = object;. It looks very old, like PHP4. To make it more modern please remove VAR keyword as it is obsolete. Second thing, please remove assigment, there is no such thing as object in the modern PHP. So your line should look like public $obj_template;. You need to add visibility to it like public / protected / private. Please read the manual here http://php.net/manual/en/language.oop5.php especially http://php.net/manual/en/language.oop5.properties.php

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.