parseCallback is a fairly simple method, even though it serves a somewhat specialized purpose. The following syntax for class names and method names can be found utilized throughout the Laravel framework:

ClassName@someMethodName

The point is that there is a string, split by the @ symbol, with the class name on the left and a method name on the right. We can use the parseCallback method to break up this string, and also specify a $default method name. If there is nothing on the right hand side of the @ symbol, or if there is no @ symbol, the $default is used as the returned method name.

The function returns an array, with two elements. The first element is the class name, and the second element will be the method name.

Signature

The signature of the parseCallback method is:

public static function parseCallback(
        $callback,
        $default = null
    );

Example Use

The following examples will highlight the values that might be returned from this function:

use Illuminate\Support\Str;

Str::parseCallback('MyClass', 'defaultValue');

The return value would be:

array(2) {
    [0] "MyClass"
    [1] "defaultValue"
}
use Illuminate\Support\Str;

Str::parseCallback('MyClass@method', 'defaultValue');

The return value would be:

array(2) {
    [0] "MyClass"
    [1] "method"
}
use Illuminate\Support\Str;

Str::parseCallback('MyClass@method@somethingElse', 'defaultValue');

The return value would be:

array(2) {
    [0] "MyClass"
    [1] "method@somethingElse"
}

It is with this example that it becomes obvious that the parseCallback will only observe the first @ symbol. Anything after the first occurance of the @ symbol will become part of the method name returned.

<?php

use Illuminate\Support\Str;

Str::parseCallback('', '');

The return value would be:

array(2) {
    [0] ""
    [1] ""
}

An example use of this function could look like this:

<?php

use Illuminate\Support\Str;

class MyClass {

    /**
     * Returns a hello message.
     *
     * @return string
     */
    public static function sayHello()
    {
        return 'Hello';
    }

}

// Would send 'Hello' to the screen.
echo call_user_func(Str::parseCallback('MyClass@sayHello'));