Home Laravel initiation of varible in __construct() VS while defining
Reply: 0

Laravel initiation of varible in __construct() VS while defining

user616
1#
user616 Published in June 19, 2018, 4:20 pm

I was generally using Laravel __construct() function in Controllers to initialize some parameters. But when I trying to call method via AJAX request, protected variables seem to be not defined in method. I.e.

protected $imageWidth;
public function __construct(){
   $this->imageWidth=500;
}

But when I initialize protected variable, while defining it, it solves my problem.

protected $imageWidth=500;

So, what is the difference between these 2 initializations and which should I use in which cases? Thanks...

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.341554 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO