开发者

php class constructor

开发者 https://www.devze.com 2023-03-23 01:41 出处:网络
Hi I have a class as follows: <?php include \'(OrderContainer.php)\'; class OrderAuthenticator { private $OrderObj;

Hi I have a class as follows:

<?php
include '(OrderContainer.php)';
class OrderAuthenticator
{
     private $OrderObj;
     public function __construct($Order)
   开发者_JAVA百科 {
        $this->OrderObj = $Order;
         echo 'Created an instance os OrderContainer<br/>';
    }

    //Misc methods.....


}
?>

Then I have a method that tries to instantiate this object

<?php
include ('OrderAuthenticator.php');

$Authenticator = new OrderAuthenticator($OrderObj);

?>

Problem is that in the object is not instantiated..... No matter what I do ..... Im new to PHP so I was wondering if there is something quite obvious here that Im not doing?

Could someone please give me a hand.. Thanks


It seems as include '(OrderContainer.php)'; should be include('OrderContainer.php'); instead.

Make sure $OrderObj is defined in the main script creating an instance of OrderAuthenticator.

To debug, be sure that PHP is showing error messages by starting with error_reporting(E_ALL); ini_set('display_errors',1); first in the main script.

Also, make sure you have no syntax error (for example, by printing "Hello world" in your script).


You need to create an $OrderObj to be passed in to the constructor


Just remove public from constructor.

0

精彩评论

暂无评论...
验证码 换一张
取 消