phplaravelsymfonynamespaceslaravel-10

Custom class in laravel 10 not found


I have created a custom class in laravel 10 located in:

App\Helpers\CompletedOrders

The class contain this code:

<?
namespace App\Helpers\CompletedOrders;

class DeliverOrdersByMail
{

    public static function DeliverOrdersToCustomerMail($OrderID)
    {
        return "mail ok ". $OrderID;
    }

}

When I try to call the class on a file:

use App\Helpers\CompletedOrders\DeliverOrdersByMail;

Route::get('test', function(){
    DeliverOrdersByMail::DeliverOrdersToCustomerMail("fgzefef");
});

I'm getting an error that the class is not found!

Class "App\Helpers\CompletedOrders\DeliverOrdersByMail" not found

Any solution please?


Solution

  • PHP short_open_tag(<?) deprecated. So you have use <?php instead of <?

    In PHP 7.4 short_open_tag remains enabled by default: Changing the default could result in code leaks during upgrades, if people rely on the default value rather than explicitly enabling them. Instead:

    • If short_open_tag is enabled and <? is used, a single deprecation notice is emitted.
    • If short_open_tag is enabled, but <? is never used, no deprecation notice is emitted (as before).
    • If short_open_tag is disabled, <? has no special meaning and is interpreted as plain text (as before).

    In PHP 8.0 the deprecation notice is converted into a parse error:

    • If short_open_tag is enabled, the use of <? is a parse error.
    • If short_open_tag is disabled, <? has no special meaning (as before).

    In PHP 9.0 support for short_open_tag is dropped entirely:

    • .<? never has special meaning, it is always interpreted as plain text.

    Ref: https://wiki.php.net/rfc/deprecate_php_short_tags_v2