Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

HttpClient: adapter always reachable through getter if specified on contructor #4925

Closed
wants to merge 3 commits into from

Conversation

Slamdunk
Copy link
Contributor

@Slamdunk Slamdunk commented Aug 2, 2013

No description provided.

@@ -205,6 +205,10 @@ public function setAdapter($adapter)
*/
public function getAdapter()
{
if ($this->adapter == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!$this->adapter) {

@Ocramius
Copy link
Member

Ocramius commented Aug 2, 2013

Looks good to me :shipit:

@ghost ghost assigned weierophinney Aug 19, 2013
weierophinney added a commit that referenced this pull request Aug 19, 2013
HttpClient: adapter always reachable through getter if specified on contructor
weierophinney added a commit that referenced this pull request Aug 19, 2013
@fkoevoets
Copy link

It seems that $this->getAdapter() on line 819 in /Zend/Http/Client.php is not called when send() is called statically from /zendoauth/library/ZendOAuth/Client.php line 201: return parent::send($request);

Therefore it can create a fatal error as mentioned by @Stiffel

@weierophinney
Copy link
Member

@fkoevoets That's not a static call; that's an extension call, and, as such, it maintains the scope of $this.

@Stiffel
Copy link

Stiffel commented Sep 4, 2013

@weierophinney Thanks for the reply. I've opened an issue for this #5074.

@fkoevoets
Copy link

@weierophinney I am sorry then. But in my case it does not run the getAdapter() from Http/Client.php . So does it run the getAdapter() from ZendOAuth/Client.php??

I see @Stiffel opened the issue for it.

@Stiffel
Copy link

Stiffel commented Sep 4, 2013

@fkoevoets I see what you were saying now. The issue is that ZendOAuth/Client.php has extended Zend/Http/Client.php and thus the call to $this->getAdapter() in the send() function of Zend/Http/Client.php is actually running the function getAdapter() in the ZendOAuth/Client.php function which returns null because $this->adapter is not set.

If I update the the call to getAdapter() in Zend/Http/Client.php to refer to its own getAdapter() function with self::getAdapter(); it works correctly. (Keeping in mind @weierophinney comment above that self::getAdapter() is not a static call and is really just saying $this)

I'll add this to the ticket I made as a suggested fix.

@weierophinney
Copy link
Member

If I update the the call to getAdapter() in Zend/Http/Client.php to refer to its own getAdapter() function with self::getAdapter(); it works correctly.

Don't you mean in ZendOAuth\Client here?

Also self:: is a static call; parent:: is not. However, if called from within an instance method, $this will be populated.

weierophinney added a commit to zendframework/zend-http that referenced this pull request May 15, 2015
…fix/client-adapter

HttpClient: adapter always reachable through getter if specified on contructor
weierophinney added a commit to zendframework/zend-http that referenced this pull request May 15, 2015
weierophinney added a commit to zendframework/zend-http that referenced this pull request May 15, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants