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

Redundant sources causing redeclaration error #6

Open
koalamer opened this issue Jan 12, 2014 · 15 comments
Open

Redundant sources causing redeclaration error #6

koalamer opened this issue Jan 12, 2014 · 15 comments
Assignees
Labels
Milestone

Comments

@koalamer
Copy link

When trying to use wsdlcache in symfony as described in the example wsdlclient12.php of the distribution, I get a redeclaration error.

The source code of this example creates instances of these classes, in this order:
wsdlcache, wsdl, nusoap_client

The autoload_classmap.php generated by composer contains these entries for them:
'wsdlcache' => $vendorDir . '/nusphere/nusoap/lib/class.wsdlcache.php',
'wsdl' => $vendorDir . '/nusphere/nusoap/lib/class.wsdl.php',
'nusoap_client' => $vendorDir . '/nusphere/nusoap/lib/nusoap.php'

The problem is that the declaration of the wsdl class is present in both class.wsdl.php and nusoap.php.

I guess, either nusoap.php should require_once those class declarations that are present in other lib files (instead of carrying a copy of them), or the classmap should map classes that are present in nusoap.php directly to nusoap.php, and not the separate class files.

@ghost ghost assigned vitorbrandao Jan 13, 2014
@vitorbrandao
Copy link
Member

@koalamer thanks for reporting. I'll check this issue tomorrow, I'll try to provide a fix by then.

@vitorbrandao
Copy link
Member

@koalamer Sorry for the delay. Have been away from my web development environment for a while.

You're right, in fact, I had my nusoap.php file modified and that's why I wasn't getting re-declaration errors. All require* directives were commented out.

Have you tried to edit vendor/composer/autoload_classmap.php and point all nusoap_ entries to nusoap.php? Does that work?

@koalamer
Copy link
Author

koalamer commented Feb 5, 2014

As far as I can remember I did try it and it did help. But then I decided not to modify any vendor files that could be overwritten by an update, so I just use this workaround: I create an empty nusoap instance before the wsdl_cache so that the classloader loads nusoap.php first, and then everything works fine.

@Hakadel
Copy link

Hakadel commented May 7, 2014

@koalamer Hello, Can you explain to me how do you fix the bug please ?

I have the same error :

PHP Fatal error: Cannot redeclare class nusoap_client in /space/www/xxx/data/htdocs/capifony/releases/20140505175343/vendor/nusphere/nusoap/lib/class.soapclient.php on line 26

@koalamer
Copy link
Author

koalamer commented May 8, 2014

@Hakadel: Just create a dummy client with a null parameter in it's constructor before you try to create the wsdlcache.
Creating this dummy client will force the class loader to load sources in an order that causes no redeclaration error, and results in only around a dozen lines of code being executed, so it should have no impact on performance.

@Hakadel
Copy link

Hakadel commented May 8, 2014

Ok thank you :)

@magr1983
Copy link

@koalamer: Hello, Could you post an example code of your solution please?

@koalamer
Copy link
Author

I solved the class duplication like this:

// this first line is the workaround that causes the right nusoap source file to load first
$client = new \nusoap_client(null);
// and then you can instantiate the wsdl cache and the client as you would normally do
$cache = new \nusoap_wsdlcache($path, $expiry);
...
$client = new \nusoap_client($wsdl);

A useful tip if you plan to send many requests with the same client instance:
Make sure to disable debug data collection or else a copy of everything you sent and received will be kept in memory and you might hit the memory_limit (as I did, until I found out about this):

$client->setDebugLevel(0);
$client->clearDebug();

@magr1983
Copy link

Thanks a lot!!!

@lucianobargmann
Copy link

Hi folks, when will this be fixed in main repository?

@vitorbrandao
Copy link
Member

Hi @lucianobargmann, I have not taken a look at this in a while, I'll check if there is something I can do about the autoloading to avoid this error. Thanks for the reminder.

@ysramirez
Copy link

@vitorbrandao vitorbrandao added this to the 0.1 milestone May 18, 2015
@vitorbrandao vitorbrandao modified the milestones: 0.2.0, 0.1.0 May 18, 2015
@vitorbrandao
Copy link
Member

Hi all, can you retest with 0.2.0 or latest dev-master? Thanks.

@cordoval
Copy link

@noisebleed it works

let's close this 👍

@cordoval
Copy link

cordoval commented Mar 1, 2017

@noisebleed this bundle is actually useless, why not just use "fergusean/nusoap": "0.9.5" directly?

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

No branches or pull requests

7 participants