Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nhayder's avatar
Level 13

Tinker not accessing my custom php class

after i watched this episode i decided to make a language menu populated from a custom class (similar to what jeffery did with the country list menu ).

https://laracasts.com/series/build-project-flyer-with-me/episodes/5

i have created a Utilities folder ( App\Http\Utilities ) and added a languages class to that Languages.php

this is my class

<?php 

namespace App\Http\Utilities;

class Languages {


    protected $Languages = [

        "English" => "en",
        "Arabic" => "ar",
        "Abkhas" => "ab",
        "German" => "de",
        "French" => "fr",
        "Turkish" => "tr"
    ];

    public function all()
    {
        return $this -> Languages;
    }
}

Since then i could't access data instead im receiving this error from tinker

PHP Fatal error: Class 'App\Http\Utilities\Languagese' not found in eval()'d code on line 1

any ideas ???

0 likes
6 replies
tykus's avatar
protected $Languages = [ // missing '='
        "English" => "en",
        "Arabic" => "ar",
        "Abkhas" => "ab",
        "German" => "de",
        "French" => "fr",
        "Turkish" => "tr"
];
1 like
nhayder's avatar
Level 13

sorry tykus i must have typed the code wrong on this forum but my original code is the correct (i have the = available on my local website )

nhayder's avatar
Level 13

OK, this is what i have now

<?php 

namespace App\Http\Utilities;

class Languages {


    protected static $Languages = [

        "English" => "en",
        "Arabic" => "ar",
        "Abkhas" => "ab",
        "German" => "de",
        "French" => "fr",
        "Turkish" => "tr"
    ];

    public static function all()
    {
        return static::$Languages;
    }
}

this is the error im receiving from tinker

PHP Deprecated:  Non-static method App\Http\Utilities\Languages::all() should not be called statically on line 1
Cronix's avatar
Cronix
Best Answer
Level 67

@nhayder It seems a config file would be more appropriate for this type of thing.

/config/languages.php

<?php

return [
    "English" => "en",
    "Arabic" => "ar",
    "Abkhas" => "ab",
    "German" => "de",
    "French" => "fr",
    "Turkish" => "tr",
];
// Get a specific key
$lang = config('languages.English'); //en

// Get the whole array
$languages = config('languages');
1 like
nhayder's avatar
Level 13

@Cronix Thank you for your comment, But what would be the advantage of using a config file rather than a custom class.

Cronix's avatar

They sound like configuration options to me, so that's what first came to mind. All you're doing is returning an array. That's what config does natively.

Please or to participate in this conversation.