从另一个类调用类方法(PHP)

I realize this is a common question and I have tried resolving it myself, but after following instructions from other answers I can't get it to work. So, this is the issue - I need to call a method from the class ClassOne in ClassTwo. So I did this:

class ClassOne{
    public function methOne($par1,$par2){
        mysql_query("insert into ps_loyalty_events (customer_id,event_id) values ('$par1','$par2') ") or die(mysql_error());
    }
}

class ClassTwo{
    private $customer;    //initialize $customer in the constructor, to be defined as an instance of ClassOne() class and used as $this->customer

    function __construct() {
        $this->customer = new ClassOne();
    }

    public function methTwo(){
        //some stuff here
        $this->customer->methOne(6,10);    //6,10 - randomly chosen parameters, irrelevant
        //some more stuff here, this doesn't get executed at all
    }
}

The priblem is not in ClassOne or the method methOne() because calling them directly from a regular PHP file in the following manner works:

$customer = new ClassOne();
$customer->methOne(6,10);

However, when I call it from the ClassTwo method, it does nothing - it just stops the execution of that function. Using try-catch doesn't seem to output anything. What am I doing wrong?

It's because your methTwo is static. When you call a static method of a class, that class is not instantiated into an object, and therefore it doesn't have the $this->customer property.

Unless there is a reason for the static method, you can change methoTwo:

public function methTwo(){

Edit: now that you have fixed that: what makes you think it isn't working? You don't do anything in methOne.

The code given is fine, see this Codepad demo of it working. That means there's some other code that we can't see that's causing the problem.

For simple solution, try to use extend classone in classtwo, so that all the method can user in classtwo by default

class class_two extends class_one

By above all the method of class one will be accessed into class two and can easily use that also. try it