NotSureILikePHP Posted August 18, 2015 Share Posted August 18, 2015 I have a class called Customer and I created a function called Customer with a parameter of id in order to load a customer based on whether they exist already using an id. When I add the function, it breaks the page. I turned error logging on but it's not helping. I get scores of errors mostly undefined index and this method is outdated but no fatal errors and no explanation of why adding this class breaks my page. Here is my code: class Customer extends VerySimpleModel implements TemplateVariable { static $meta = array( 'table' => CUST_TABLE, 'pk' => array('cust_id'), 'joins' => array( 'location' => array( 'constraint' => array('cust_id' => 'loc.cust_id'), ), 'service' => array( 'constraint' => array('service_level' => 'service.id'), ), ), ); var $id; var $name; var $contact; var $fname; var $lname; var $contact_phone; var $phone_number; var $fax_number; var $location; var $domain; var $service_level; var $row; var $address; var $_location = null; public function Customer( $id=0 ) { echo 'here'; $this->id=0; if($id && ($info=$this->getInfoById($id)) ){ $this->row=$info; $this->id=$info["id"]; $this->name=$info["cust_name"]; $this->domain=$info["domain"]; $this->location=$this->getLocationInfo($id); $this->service_level=$info["service_level"]; } } } //page that is loading the Grid data $custs = Customer::objects(); I think it has something to do with the way that $custs is being loaded but I can't find any good detail on what objects() even is in php so I can't really figure out exactly what that line is doing and if that's even the problem. Quote Link to comment https://forums.phpfreaks.com/topic/297850-construct-breaks-project/ Share on other sites More sharing options...
scootstah Posted August 18, 2015 Share Posted August 18, 2015 What does "breaks the page" mean? And where did you turn error logging on? If it is not turned on in the php.ini itself, then certain types of fatal errors will occur before the error reporting in the code is executed - thus you won't get any errors. Make sure that error_reporting and display_errors are turned on in the php.ini, and then restart apache. Quote Link to comment https://forums.phpfreaks.com/topic/297850-construct-breaks-project/#findComment-1519175 Share on other sites More sharing options...
JonnoTheDev Posted August 18, 2015 Share Posted August 18, 2015 You are using PHP 4 syntax that is obsolete. You should not use the var keyword, nor should you give a method the same name as the class. In PHP 4 this was how you defined the constructor. I suggest you read up on how to use classes in PHP 5. Refactored <?php class Customer extends VerySimpleModel implements TemplateVariable { public static $meta = array( 'table' => CUST_TABLE, 'pk' => array( 'cust_id' ), 'joins' => array( 'location' => array( 'constraint' => array( 'cust_id' => 'loc.cust_id' ), ), 'service' => array( 'constraint' => array( 'service_level' => 'service.id' ), ), ), ); public $id; public $name; public $contact; public $fname; public $lname; public $contact_phone; public $phone_number; public $fax_number; public $location; public $domain; public $service_level; public $row; public $address; private $_location = null; public function getCustomer( $id = 0 ) { echo 'here'; $this->id=0; if($id && ($info=$this->getInfoById($id)) ){ $this->row=$info; $this->id=$info["id"]; $this->name=$info["cust_name"]; $this->domain=$info["domain"]; $this->location=$this->getLocationInfo($id); $this->service_level=$info["service_level"]; } } } //page that is loading the Grid data $custs = Customer::objects(); Quote Link to comment https://forums.phpfreaks.com/topic/297850-construct-breaks-project/#findComment-1519188 Share on other sites More sharing options...
NotSureILikePHP Posted August 18, 2015 Author Share Posted August 18, 2015 The error reporting is not turned on in the php.ini file. It was just locally in the page and by breaks the page it was solid white. Though now, it just displays no record in the grid. I just got back in so I'll try turning on errors in the ini file and that should help. Also I will change all his var code to public and read up on the new php. Quote Link to comment https://forums.phpfreaks.com/topic/297850-construct-breaks-project/#findComment-1519206 Share on other sites More sharing options...
NotSureILikePHP Posted August 18, 2015 Author Share Posted August 18, 2015 Just to make sure I am doing this accurately I changed the code to this class Customer extends VerySimpleModel implements TemplateVariable { static $meta = array( 'table' => CUST_TABLE, 'pk' => array('cust_id'), 'joins' => array( 'location' => array( 'constraint' => array('cust_id' => 'loc.cust_id'), ), 'service' => array( 'constraint' => array('service_level' => 'service.id'), ), ), ); public $id; public $name; public $contact; public $fname; public $lname; public $contact_phone; public $phone_number; public $fax_number; public $location; public $domain; public $service_level; public $row; public $address; public $_location = null; public function _construct( $id=0 ) { echo 'here'; $this->id=0; if($id && ($info=$this->getInfoById($id)) ){ $this->row=$info; $this->id=$info["id"]; $this->name=$info["cust_name"]; $this->domain=$info["domain"]; $this->location=$this->getLocationInfo($id); $this->service_level=$info["service_level"]; } } } \\and I call it like this from the other page $cust = new Customer($_REQUEST['id']); If I do that it should go to the construct function correct? Because I can't get it to print 'here'. Quote Link to comment https://forums.phpfreaks.com/topic/297850-construct-breaks-project/#findComment-1519207 Share on other sites More sharing options...
Barand Posted August 18, 2015 Share Posted August 18, 2015 should be __construct() 2 underscores Quote Link to comment https://forums.phpfreaks.com/topic/297850-construct-breaks-project/#findComment-1519209 Share on other sites More sharing options...
NotSureILikePHP Posted August 19, 2015 Author Share Posted August 19, 2015 Thanks Quote Link to comment https://forums.phpfreaks.com/topic/297850-construct-breaks-project/#findComment-1519240 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.