0

I was just going through the curl library for codeigniter to understand the code. Here is the link. There is this function __call() which I am not sure about. Is it an inbuilt function in CI? I suppose it is called whenever any method of this library is called, for example using

$this->curl->simple_get();

Can someone please shed the light. I couldn't find much info on the codeigniter user guide.

2 Answers 2

4

No - __call() is a php function. It is known as one of the magic methods.

The magic method __call() is to undeclared methods what __get() and __set() are to undeclared data member.

These methods are automatically called internally when the program tires to execute a method that has not been defined within the class at the time of development.

__call() takes two arguments. The first argument is the name of the undeclared method invoked by the program and the second is an array that contains a list of parameters passed to the undeclared array

Example

class Customer {

    public function __call($name, $args) {
        var_dump($name);
        echo "\n";
        var_dump($args);
        echo "\n";
    }
}

$c = new Customer();
$c->setName("some","name");

Ref

Sign up to request clarification or add additional context in comments.

Comments

0

__call() is a magic function in OOP, it's invoked if the function isn't found. So because there is no simple_get() function inside the Curl class, the __call() function will be called, and you can see, there is a comment there, what will happen with the method call.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.