Jump to content

Recommended Posts

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 by Ch0cu3r
fixed bbcode
Link to comment
https://forums.phpfreaks.com/topic/297837-deleted-class-and-still-calling-it/
Share on other sites

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.