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

Cannot redeclare Patchwork\redefine() #49

Closed
Purus opened this Issue Mar 7, 2017 · 5 comments

Comments

Projects
None yet
2 participants
@Purus

Purus commented Mar 7, 2017

I guess the below question looks like a newbie PHP question. But I wanted to hear the solution from the developer of this great package.

I am developing a plugin for a CMS which uses Patchwork library. The CMS has another plugin using Patchwork.

Due to 2 declaration of same classes/functions, I am getting the fatal error as below.

Fatal error: Cannot redeclare Patchwork\redefine()

If I have to re-declare all classes/function to a new namespace, what will be the best approach? Using function_exist method will help?

@antecedent

This comment has been minimized.

Show comment
Hide comment
@antecedent

antecedent Mar 7, 2017

Owner

Indeed, you might want to surround your own include statement for Patchwork with if (!function_exists('Patchwork\replace')) { ... }, so that it's imported only once.

(Older versions used to have replace instead of redefine; it's available as an alias in 2.0 too.)

However, I'll address this in Patchwork's code too, as this is a very general issue.

Also, I'm awfully sorry, but I couldn't quite understand the concern in your last paragraph, so there might still have been some miscommunication.

And thank you for the kind words :)

Owner

antecedent commented Mar 7, 2017

Indeed, you might want to surround your own include statement for Patchwork with if (!function_exists('Patchwork\replace')) { ... }, so that it's imported only once.

(Older versions used to have replace instead of redefine; it's available as an alias in 2.0 too.)

However, I'll address this in Patchwork's code too, as this is a very general issue.

Also, I'm awfully sorry, but I couldn't quite understand the concern in your last paragraph, so there might still have been some miscommunication.

And thank you for the kind words :)

@Purus

This comment has been minimized.

Show comment
Hide comment
@Purus

Purus Mar 8, 2017

Thanks for your time on the response.

My question is about renaming the namespace to something else. like Patchwork2. If I have to do this, how should I start?

Purus commented Mar 8, 2017

Thanks for your time on the response.

My question is about renaming the namespace to something else. like Patchwork2. If I have to do this, how should I start?

@Purus

This comment has been minimized.

Show comment
Hide comment
@Purus

Purus Mar 8, 2017

Checking for function does not help.

if(!function_exists('Patchwork\redefine')){
    require_once $classDir . "autoload.php";
    require_once $classDir . "antecedent" . DS . "patchwork" . DS . "Patchwork.php";
}

I still get the same error.

Fatal error: Cannot redeclare Patchwork\redefine() (previously declared in C:\Program Files\VertrigoServ\www\plugins\email_template\classes\antecedent\patchwork\Patchwork.php:17) in C:\Program Files\VertrigoServ\www\plugins\email_logs\classes\antecedent\patchwork\Patchwork.php on line 25

Purus commented Mar 8, 2017

Checking for function does not help.

if(!function_exists('Patchwork\redefine')){
    require_once $classDir . "autoload.php";
    require_once $classDir . "antecedent" . DS . "patchwork" . DS . "Patchwork.php";
}

I still get the same error.

Fatal error: Cannot redeclare Patchwork\redefine() (previously declared in C:\Program Files\VertrigoServ\www\plugins\email_template\classes\antecedent\patchwork\Patchwork.php:17) in C:\Program Files\VertrigoServ\www\plugins\email_logs\classes\antecedent\patchwork\Patchwork.php on line 25

@antecedent

This comment has been minimized.

Show comment
Hide comment
@antecedent

antecedent Mar 9, 2017

Owner

(My apologies again, I'd been working on a take-home assignment for a job interview for the past few days.)

I see that this might not work if the other copy of Patchwork is autoloaded at an unpredictable point in time. For now, I guess the only thing I can suggest is manually editing out the conflicting include statement for Patchwork. However, I'm already working on a more reliable fix.

As for your first response: running two copies of Patchwork simultaneously (if you really mean that) would be really difficult to accomplish. The preprocessing component (CodeManipulation) is the main obstacle here.

Owner

antecedent commented Mar 9, 2017

(My apologies again, I'd been working on a take-home assignment for a job interview for the past few days.)

I see that this might not work if the other copy of Patchwork is autoloaded at an unpredictable point in time. For now, I guess the only thing I can suggest is manually editing out the conflicting include statement for Patchwork. However, I'm already working on a more reliable fix.

As for your first response: running two copies of Patchwork simultaneously (if you really mean that) would be really difficult to accomplish. The preprocessing component (CodeManipulation) is the main obstacle here.

@antecedent

This comment has been minimized.

Show comment
Hide comment
@antecedent

antecedent Mar 9, 2017

Owner

Please upgrade to 2.0.1 :)

Owner

antecedent commented Mar 9, 2017

Please upgrade to 2.0.1 :)

@antecedent antecedent closed this May 3, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment