NotSureILikePHP Posted August 17, 2015 Share Posted August 17, 2015 (edited) Okay I thought I was finally starting to get the hang of php so I went through trying to clean up some code. I changed all instances of my class Cust to Customer just for clarification. That's when I ran into a weird problem. I had a page that shows a grid of customers and it was calling this function //code that calls the class $custs = Customer::objects(); //this is the class declaration 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 $cust_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; //this is the function causing problems function Cust( $id=0 ) { $this->id=0; if($id && ($info=$this->getInfoById($id)) ){ $this->row=$info; $this->id=$info["cust_id"]; $this->cust_name=$info["cust_name"]; $this->domain=$info["domain"]; $this->location=$this->getLocationInfo($id); //$this->note=$this->getNotes($id); $this->service_level=$info["service_level"]; } } When I change that last function to Customer it breaks my grid and the grid doesn't load. However, nothing in my code is now calling that function as doing a search on my entire project in eclipse gives me no results. If I leave it as Cust my grid works but when I click on a customer to edit that doesn't work unless the function is named Customer. What happened and why is this code still calling a function by his old name? Edited August 17, 2015 by Ch0cu3r fixed bbcode Quote Link to comment https://forums.phpfreaks.com/topic/297837-deleted-class-and-still-calling-it/ Share on other sites More sharing options...
Ch0cu3r Posted August 17, 2015 Share Posted August 17, 2015 Because that function is most likely being treated as a constructor. In OOP (using older PHP 4 sytax, which what your code uses) when a function is named the same as the class it will be called automatically when a new instance of the class is initialized (created eg $customer = new Customer()). So if you rename your class to customer you must rename the cust() function the same. This why this is happening when I click on a customer to edit that doesn't work unless the function is named Customer. Quote Link to comment https://forums.phpfreaks.com/topic/297837-deleted-class-and-still-calling-it/#findComment-1519116 Share on other sites More sharing options...
NotSureILikePHP Posted August 17, 2015 Author Share Posted August 17, 2015 I figured that part out but when I name it to Customer another page doesn't work (my data grid page). It only works when the function is named Cust even though I have removed every instance of that and changed it to customer. Quote Link to comment https://forums.phpfreaks.com/topic/297837-deleted-class-and-still-calling-it/#findComment-1519117 Share on other sites More sharing options...
Ch0cu3r Posted August 17, 2015 Share Posted August 17, 2015 PHP must be calling the cust() function from somewhere, it maybe being called as part of callback, from a function like call_user_func_array When you name the function as Cust use debug_print_backtrace() inside the function. Maybe this help you identify where it is being called from. Quote Link to comment https://forums.phpfreaks.com/topic/297837-deleted-class-and-still-calling-it/#findComment-1519118 Share on other sites More sharing options...
NotSureILikePHP Posted August 17, 2015 Author Share Posted August 17, 2015 Thanks I will try that backtrace. Haven't seen that trick yet. Quote Link to comment https://forums.phpfreaks.com/topic/297837-deleted-class-and-still-calling-it/#findComment-1519119 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.