Jump to content

Deleted class and still calling it


NotSureILikePHP

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
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.
Link to comment
Share on other sites

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.