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!

Member Avatar for diafol

Fo this:

 $this->IceTray = $IceTray;

You need so declare the

 private $IceTray;

in the class.

Oh, alright I will try that when I have the chance, thanks!

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.

Member Avatar for diafol
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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.