What is the proper way to create an object of another class in PHP? -



What is the proper way to create an object of another class in PHP? -

i have 1 utility class called emailutility.php follows:

<?php class emailutility { public function sendmail($subject,$body) { } } ?>

i have 2 more class, want utilize sendmail method of emailutility class. have first class (test1.php) uses emailutility below.

<?php include("emailutility.php") class test1 { $emailutil=new emailutility(); $emailutil->sendmail("",""); } ?>

now, when tried utilize same emailutility class in class on same way, not working. but, when remove utilize of emailutility test1, test2 working fine. not working means when browsing, no html generated other part of code in same file well.

<?php include("emailutility.php") class test2 { $emailutil=new emailutility(); $emailutil->sendmail("",""); } ?>

how can utilize 1 class in multiple other classes? also, 1 class can included 1 time in php?

from understand, including emailutility.php file multiple times , causes programme crash since classes beingness overwritten. replace line below

include("emailutility.php");

with

include_once("emailutility.php");

php

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -