4

I'm accessing Laravel's helper function base_path() in a model class. I'm running Laravel 4.1.23

I'm getting the following error:

    PHP Fatal error:  Call to a member function make() on a non-object in /Applications/mampstack-5.4.23-0/frameworks/laravel/vendor/laravel/framework/src/Illuminate/Support/helpers.php on line 492

The weird thing is I tested the function call in phpunit, and it works perfectly. Any help would be appreciated.

My project has the following dependencies:

"require": {
        "laravel/framework": "4.1.*",
        "cpliakas/git-wrapper": "1.1.*",
        "rmccue/requests": "v1.6.0",
        "phpseclib/phpseclib": "0.3.*"
    }
Zach Mance
  • 95
  • 9
  • Not sure if the issues are related but there seems to be a bug filed under the same error message on Github here is the link: https://github.com/laravel/framework/issues/854 **Edit:** And here is another one I dug up which points to the helpers.php file as well: https://github.com/patricktalmadge/bootstrapper/issues/125 – adamj Mar 14 '14 at 00:18
  • did you run composer dump-autoload? – marcanuy Mar 14 '14 at 01:25
  • I did run dump-autoload. I believe the problem is I was running my model tests by just running "php mymodel.php" from the command line. I was testing minor things just after the class definition. The reason I think this is the problem is because it works with phpunit. – Zach Mance Mar 14 '14 at 04:54
  • That sounds credible. Running your model tests directly would mean that you're bypassing loading of key framework components - hence the non-object. – petercoles Mar 15 '14 at 23:18

1 Answers1

0

Laravel is telling you that it cannot execute make() on a non-object. If this is the line:

 app()->make('path.base').($path ? '/'.$path : $path);

The non-object is the returning value of the function

 app()

Which might have been overriden by one of your packages or own helpers. This is the code that creates this function:

if ( ! function_exists('app'))
{
    /**
     * Get the root Facade application instance.
     *
     * @param  string  $make
     * @return mixed
     */
    function app($make = null)
    {
        if ( ! is_null($make))
        {
            return app()->make($make);
        }

        return Illuminate\Support\Facades\Facade::getFacadeApplication();
    }
}

As you can see, Laravel does not create it unless it doesn't exists. Try to execute:

var_dump( app() );

Inside your model to see what you have in return. It must start with

object(Illuminate\Foundation\Application)[2]
  protected 'booted' => boolean true
  protected 'bootingCallbacks' => 
    array (size=0)

If it's not an object of Illuminate\Foundation\Application, try to find where is the app() function and stop using it.

Antonio Carlos Ribeiro
  • 86,191
  • 22
  • 213
  • 204