-
Notifications
You must be signed in to change notification settings - Fork 446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cli usage #775
Comments
In CLI mode, Syntax in CLI mode is |
I'm using the script like this:
I'm not using F3 for this particular script, it's a utility script that is being used to import data into models. It's part of the repo, it just shouldn't be handled at all by F3. The common thing between the F3 controlled pages and my script, is an include file that references the composer autoloader:
I'm using composer in this script for other libraries and not f3 (so turning off composer is not an option). Clearly f3 dieing because |
Maybe you can clarify which version of PHP you're using as well as an example of The |
HI. Can you clarify what autoloader are you using? |
Version of PHP:
I'm using the composer autoloader - I've only brought in F3 via composer and it's being loaded up via autoloader_files.php. In my example, both the web route (using F3) and the back end script use the same include, which references the composer autoloader. In my web route, I .htaccess files to index.php - my back end script is a completely separate php file and I don't actually want to use F3 for it. |
Regardless of whether there is some issue with argument parsing, I think the F3 autoloader is also an issue. Its instantiating of Base when its not necessarily needed. The autoloading needs to be rewritten. Known issue - see #741. There maybe some other legit issue going on here with args. Not sure. |
I'm not familiar with composer but judging from the docs and from the project composer.json I understand that base.php is required automatically (instead of being autoloaded). That could explain why Any composer user to confirm that behaviour? |
@xfra35 I can confirm that is what is happening. |
The question is: why should an autoloader care if an object is instantiated, or for that same reason, should an autoloader care if a PHP constant suddenly appeared? It shouldn't. It should only care about loading the class... whatever happens next is up to the app. Not Composer, not the framework. Where does the responsibility lie? |
As I understand it, the current composer.json is defined in such a way that F3 is automatically required before we even call it. In other words, when using Composer, people get an autoloader + an automatic This behavior was introduced in #721. |
I'm ok (kind of) with it requiring Ignoring the fact that it's automatically requiring the file, I should be able to use other scripts and not use F3 if I don't want to. My view is that if I have a command line script to run in the same directory as the project I'm using F3 (I can't be the only one doing this, right?), then F3 should have a responsibility to not break the script because of a missing variable - missing because it's come from the CLI and not handled. |
The thing is that the framework works perfectly in CLI mode. So the error comes from parse_url choking on something. Could be a PHP bug.. could be caused by your argument1. Hence my request to see it. |
In order to help debug this issue, you could add a |
for me the whole issue reads like this: |
He's not using |
so then why the class is included / required? the constructor does not load by any magic |
Here's argv:
The first param is a URL - which doesn't have a slash at the end, which means parse_url doesn't have a A defensive check to make sure it exists would do the trick. Or stop base.php being loaded - seeing as I'm not using it at all then that would make the most sense to me. |
@KOTRET because of this line: https://github.com/bcosca/fatfree/blob/master/composer.json#L16 |
yes, but in general requiring a file does not mean to instantiate the class in it. This has been done for convenience if F3 is the starter app. So in this case the last line in |
@KOTRET when would one need to require @rgubby you're right about Couldn't there be another way to configure composer.json to avoid |
$f3 = require('path/to/base.php'); already creates an instance. In this case its more convenient instead of require('path/to/base.php');
$f3 = new \Base(); using an autoloader you can call back to the topic this means: as soon as the file gets |
On this point: the correct way of invoking the framework is Anyway this doesn't relate to the current issue, which is: without Composer: $f3=require('lib/base.php');//<-- base.php explicitly required and loaded with Composer: require('vendor/autoload.php');//<-- base.php NOT explicitly required BUT loaded anyway |
ah okay, then your suggestion is correct: as of the documentation the usage of autoload files will require the file:
|
Exactly. Also a side effect is that other libraries are not autoloaded (template.php, db/sql.php etc..). I think that classmap fixes it all. |
@xfra35 you are right with |
What do you mean? If |
read the last line in base.php, this will create one instance automatically on requiring the file?
|
I still don't get it. The last line is You can call |
The bug is the last line itself. This will create an instance of |
I feel like this conversation is looping ;) Indeed it will create an instance, but that won't result in having two instances at any time. |
@xfra35 : the problem is that the error is thrown in the constructor, so it DOES matter if it will create an instance or not. |
Ok. But why would anybody require |
it is expected as of the composer entry you mentioned ^^ The bug itself will be fixed with the suggestion, but the general discussion i initiated will remain. |
@xfra35 so composers "Classmap" option somehow make the require of the base class lazy loading? can you confirm that, and that this CLI issue should be solved with it? |
@xfra35 I can confirm that this is working as expected. My script is now running exactly as I want it to and does not halt. I've also noticed that a PHP notification I was hiding with php.ini settings, which appeared due to strict checking in F3 has now gone again. Ignoring the fact that I'm removing certain types of PHP error messages, it's a good thing that F3 isn't trying to interfere with this. Thanks for getting to the bottom of it! |
I include F3 in a project, but then have an independent script that happens to use the same autoloader, it pulls in F3 (even though I don't need it) and causes this error to appear:
The problem happens here: https://github.com/bcosca/fatfree/blob/master/lib/base.php#L1893
It's because in CLI mode,
$uri['path']
doesn't exist. Maybe something like this would do the trick:The text was updated successfully, but these errors were encountered: