0

Hello! So I currently have a class titled Appliciation which contains a method called start.

<?php
class Application {
    /*
     * Application class
    */
    public function __construct($IceTray){
        $this->IceTray = $IceTray;
    }
    /* Starts application */
    public function start(){
        /* Confiures error reporting */
        $this->IceTray->Error->configure();

        $Path = $IceTray->Path;
        include APPDIR.'/paths.php';
        $Path->start();
    }
}

I'm including this file that will only use the Path object. When the script is run I get this error:

Fatal error: Call to a member function set() on a non-object in C:\wamp\www\IceTray\application\paths.php on line 16

So obviously the Path variable/object isn't in the scope of the included file for some reason, is this different because it's inside a method? This worked fine procedurally. Thanks for any suggestions.
Also I did consider maybe using eval, but that could have issues... Again thanks for any suggestions!

2
Contributors
5
Replies
17
Views
4 Years
Discussion Span
Last Post by NardCake
0

Fo this:

 $this->IceTray = $IceTray;

You need so declare the

 private $IceTray;

in the class.

Edited by diafol

0

New code

<?php
class Application {
    /*
     * Application class
    */
    private $IceTray;
    public function __construct($IceTray){
        $this->IceTray = $IceTray;
    }
    /* Starts application */
    public function start(){
        /* Confiures error reporting */
        $this->IceTray->Error->configure();

        $Path = $IceTray->Path;
        include APPDIR.'/paths.php';
        $Path->start();
    }
}

Still not working with your solution :|
Any other suggestions?
Just to clarify in the included file I would like to use the Path object/variable.

Edited by NardCake

0
public function start(){
    /* Confiures error reporting */
    $this->IceTray->Error->configure();
    $Path = $IceTray->Path;
    include APPDIR.'/paths.php';
    $Path->start();
}

The line:

$Path = $IceTray->Path;

Can't work as $IceTray does not exist (scope). This is the whole reason for $this->IceTray, so do this:

public function start(){
    /* Confiures error reporting */
    $this->IceTray->Error->configure();
    $Path = $this->IceTray->Path;
    include APPDIR.'/paths.php';
    $Path->start();
}

We're assuming that the IceTray object has all the methods and properties that you're using. Also not clear what including that file does for the $Path->start(). Perhaps it would be clearer if the file was included or read in the IceTray->Path->start() method of the IceTray class.

0

Oh wow what a simple mistake on my part, all I needed was another eye I suppose, thanks for the help!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.