Support the ongoing development of Laravel.io →
Laravel Eloquent
Last updated 2 weeks ago.
0

Hey!

I'm assuming this is an object, right?

You could try defining the variables outside the constructor first. So like this:

class Something
{
    public $name;
    public $zip_code;
    public $phone_number;

    public method __construct()
    {
        $this->name = "John";
        $this->zip_code = "abcd12";
        $this->phone_number = "0123456789";
    }

    public method getValues()
    {
        // just checking:
        dump ($this->name);
    }
}

I think that should work.

Now, if it's actually a controller, it might not work that way. But then again, I can't see any use case for that? If the values are actually static, define them as config variables. If they're variable, they probably come from the request and don't need to be set in the constructor.

0

Sign in to participate in this thread!

LaraJobs

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2022 Laravel.io - All rights reserved.