Tuesday, April 3, 2018

How to use one PHP class to Another php class


 Here i have create the 3 php files .

MyClass1.php

  <?php
  class MyClass1 {
   public $nm="brij";
}

?>


MyClass2.php
<?php
  class MyClass2 {
   public $nm="brij2";
}

?>

Test.php

<?php
spl_autoload_register(function ($class_name) {
    include $class_name . '.php';
});

$obj  = new MyClass1();
$obj2 = new MyClass2();
echo $obj->nm;
echo $obj2->nm;
?>

No comments:

Post a Comment

Featured Post

What is JavaScript? What is the role of JavaScript engine?

  The JavaScript is a Programming language that is used for converting static web pages to interactive and dynamic web pages. A JavaScript e...