Skip to content
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

Bug: Extended Namespaces are preventing files from importing #231

Open
seb86 opened this issue Jul 6, 2022 · 6 comments
Open

Bug: Extended Namespaces are preventing files from importing #231

seb86 opened this issue Jul 6, 2022 · 6 comments

Comments

@seb86
Copy link

seb86 commented Jul 6, 2022

I'm not able to get any file that uses Namespaces extensively. A single Namespace is acceptable but longer Namespaces are ignored.

Any chance of getting this fixed or know of a workaround?

Example of a class using Namespaces that are ignored.

<?php
namespace MainNamespace\SecondName;

use \Automattic\WooCommerce\Checkout\Helpers\ReserveStock;
@jrfnl
Copy link
Member

jrfnl commented Jul 6, 2022

use \Automattic\WooCommerce\Checkout\Helpers\ReserveStock;

Without an opinion on this issue: use statements always need the fully qualified name, so please don't use a leading backslash.

@seb86
Copy link
Author

seb86 commented Jul 6, 2022

use \Automattic\WooCommerce\Checkout\Helpers\ReserveStock;

Without an opinion on this issue: use statements always need the fully qualified name, so please don't use a leading backslash.

Then I cant use the namespace as it is outside my plugin.

Anyway either line stops importing the file.

use Namespace does work but anything past that seems to stop. I'm sure a tweak somewhere can correct this. Just need to know where.

@jrfnl
Copy link
Member

jrfnl commented Jul 6, 2022

Note: still off-topic.

Then I cant use the namespace as it is outside my plugin.

I honestly don't know what you mean. Sounds more like an autoloading issue.
use statements with a leading backslash is a big no-no and whether something is from inside or outside your plugin is completely irrelevant to that.

@seb86
Copy link
Author

seb86 commented Jul 7, 2022

Anyway back on topic.

If the class is like this then it imports fine.

<?php
namespace MainNamespace;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Cart Cache for Cart REST API.
 *
 * This handles the cart data in cache before the totals are calculated.
 *
 * @since 3.1.0
 */
class ClassName {

But if I have a class like so then it is not importing.

<?php
namespace MainNamespace\SecondName;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Cart Cache for Cart REST API.
 *
 * This handles the cart data in cache before the totals are calculated.
 *
 * @since 3.1.0
 */
class ClassName {

Any clue why?

@seb86
Copy link
Author

seb86 commented Oct 14, 2022

So after spending some more time on why it's not importing certain files in my plugin. I found out that it doesn't like any lines or even parameters in a function that are using a backslash.

I believe I have narrowed it down to the dependency your using called Reflection which is what parses the contents of the files being imported. This parser plugin is currently using v3.0

Perhaps we could have it updated?

If a new issue with examples is required please let me know.

@kkmuffme
Copy link

It's essentially #228 - basically all issues that pop up here now are bc of the ancient Reflection version used here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants