laravel-async-queue icon indicating copy to clipboard operation
laravel-async-queue copied to clipboard

Weird behaviour in including

Open aalyusuf opened this issue 10 years ago • 6 comments

Hi,

I have this class which i included in composer.json:

    "files": ["app/lib/coolstuff/A.class.php"]

A.class.php:

<?php
require_once 'functions.php';

class A
{
    public function __construct()
    {
        if (function_exists('foobar')) {
            file_put_contents("log.txt", "yes");
        }
        else{
            file_put_contents("log.txt", "no");
        }
    }
}

And functions.php :

function foobar(){
 // do something complicated
}

when using async, function foobar isn't defind but functions.php is included ( using get_included_files ) log.txt has "no" , log.txt path is root path

when using sync driver, foobar is defined and log.txt has "yes" , log.txt path is public_path

aalyusuf avatar Dec 13 '14 16:12 aalyusuf

I don't now, can you include the full absolute path?

barryvdh avatar Dec 13 '14 18:12 barryvdh

Hi,

/Applications/MAMP/htdocs/test/app/lib/coolstuff/A.class.php
/Applications/MAMP/htdocs/test/app/lib/coolstuff/functions.php

/Applications/MAMP/htdocs/test/log.txt
/Applications/MAMP/htdocs/test/public/log.txt

aalyusuf avatar Dec 13 '14 22:12 aalyusuf

I mean in Your code, instead of the relative ones.

barryvdh avatar Dec 13 '14 22:12 barryvdh

Ah sorry, tried that.. same issue. Files are being included but functions arent being defined. Same code works fine with sync driver

aalyusuf avatar Dec 13 '14 22:12 aalyusuf

Why not autoload the functions file with composer also? Sync is different, that runs in the same request so has access to everything that is already loaded in that request cycle. Async is a entirely new request.

barryvdh avatar Dec 13 '14 23:12 barryvdh

Project i'm on has seven or eight files, would be kinda messy. Shouldn't Laravel helpers be defined too ?

aalyusuf avatar Dec 13 '14 23:12 aalyusuf