0

I've included errors and warnings in my PHP.INI and the last 2 errors were solved, they were mostly "Creating default object from empty value" - The issue is that I have no idea where to start here.

With the previous (same) error it was easier since there was a public class extended from the current and had an object instantiated so all it took was nesting the instance in an !isset condition.

Yet here

public function forward( $forward )
{
     $this->viewBean->_forward = $forward;
}

The error is pointing on the $this. There is no object instantiation and the method above is part of an Abstract Class identified as BaseController Since I can't instantiate an object from an Abstract Class, I truly have no idea how to continue to debug this PHP warning.

Please let me know if any info is amiss, I'll comment back

3
  • How do you call this method, show code please Commented Mar 29, 2016 at 11:42
  • You can't create abstract class object..... Commented Mar 29, 2016 at 11:46
  • 1
    This is not possible, I assume viewBean returns an instance which then _forward is a variable you're trying to write to inside the Object? this won't be saved in memory since where have you actually stored it??? (clue: you havent) Commented Mar 29, 2016 at 11:49

1 Answer 1

1

Abstract classes are not supported in PHP like this.

You must store the Object as a local variable for it to 'remember' its data.

class Example
{
    public $abstract;
    public function forwards($forwards)
    {
        $this->abstract = $this->viewBean;
        $this->abstract->_forwards = $forwards;
    }
    public function viewBean()
    {
        return new OtherClass;
    }
}

// TODO: Add your other class with its Public variable

Example of usage:

// <-- for newer supported php versions -->
$exampleClass = (new Example)->forwards("add me!");
echo $exampleClass->abstract->_forwards;

// <-- for depreciated php versions -->
$exampleClass = new Example;
$exampleClass->forwards("add me!");
echo $exampleClass->abstract->_forwards;

Although this fixes your issue, I do not see why you'd want to ever forward a variable? You can use the extends to create child Classes which inherits the properties and methods held inside the context.

There is always callback methods you can use also.

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.