Laravel: Do facades really create new objects when calling methods?

I have a demo class, usually linked through

$ this-> app-> bind ('demo', function () {return new Demo ();}

Sets the facade

protected static function getFacadeAccessor () {return 'demo'; }

The class itself looks like this:

class demo 
    {

        private $ value1;        
        private $ value2;        

        public function setVal1 ($ value)
        {
            $ this-> value1 = $ value;
        }

        public function setVal2 ($ value)
        {
            $ this-> value2 = $ value;
        }

        public function getVals ()
        {
            return 'Val 1:'. $ this-> value1. 'Val 2:'. $ this-> value2;
        }   

    }

I was told that if I use the facade in this class, Laravel will create a class object and then call a method on this object, for example:

$app->make['demo']->setVal1();     

Butt I checked a few more and found this very strange (at least for me) behavior:

If i do

Demo :: setVal1 ('13654');
and
Demo :: setVal2 ('random string')

I cannot use Demo :: getVals () to retrieve the values ​​I just created, should I? Since each time the facade method is used, an instance of a new object is created, and how can one object retrieve the properties of another object? There should be three different instances, but still I can get the properties from these other instances ...

I thought this was possible only if I connected the class with App :: singleton, and not through App :: bind?

+4

All Articles