Toggle navigation
Genres
Frontend (2)
JavaScript (6)
Database (2)
Linux Server (3)
Web Apps (4)
Misc (4)
Search
List
New Tutorials
Last Modified Tutorials
</>
Code examples
code
smiko
backend
php
oop
classes_objects
z957object_as_property.php
z957object_as_property.php
<?php /**Primjer pokazuje kako svojstvo moze biti objekt**/ class MojaKlasa { public $sv1,$sv2; //moraju biti public public function __construct($p1,$p2){ $this->sv1=$p1; $this->sv2=$p2; } } class DrugaKlasa { public $dsv; public function __construct(){ $obj=new MojaKlasa('svojstvo1','svojstvo2'); //instanca unutar klase $this->dsv=$obj; //svojstvo postaje objekt } } $obj2=new DrugaKlasa; echo $obj2->dsv->sv1; ?>
Reload page
Preview
W3C validation
Edit Code