Is there a way to instantiate a class and define the variables all on one line? Instantiating it, then defining all the variables, then calling it, is taking up almost as many lines as the raw html code would by itself.
I have a class like so:
class Gallery { public $image; public $text; public $heading; public $link; public function Item() { echo ' <div class="gallery_item"> <div class="gallery_image"> <img src="' . $this->image . '"> </div> <div class="gallery_text"> <h3> ' . $this->heading . '</h3> <p> ' . $this->text . '</p> <a href="' . $this->link . '">View Live Site</a> </div> </div> '; } } And then I call it by using:
<?php $Gallery_1 = new Gallery(); $Gallery_1->image = "img/test.jpg"; $Gallery_1->heading = "Test Object"; $Gallery_1->text = "This is a sample text description for the gallery items. It can be long or short"; $Gallery_1->link ="#"; $Gallery_1->Item(); ?> Can I do something like below instead? The below code doesn't work, but is there something similar?
$Gallery_1 = new Gallery(image->"img/test.jpg", heading->"test", text->"text", link->"#"); $Gallery_1-Item();