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

Undefined offset: 1 #39

Closed
battle-mage opened this issue Oct 31, 2016 · 5 comments
Closed

Undefined offset: 1 #39

battle-mage opened this issue Oct 31, 2016 · 5 comments
Labels

Comments

@battle-mage
Copy link

battle-mage commented Oct 31, 2016

We are facing a problem since the last update while Curl is trying to extract additional params.
https://github.com/linslin/Yii2-Curl/blob/master/Curl.php:

if (preg_match('~^charset=(.+?)$~', trim($possible_charset), $matches) && isset($matches[1])) {
    $this->responseCharset = strtolower($matches[1]);
}

shouldn't we use array_key_exists(1,$matches) instead of isset($matches[1])?

@linslin linslin added the bug label Oct 31, 2016
@linslin
Copy link
Owner

linslin commented Oct 31, 2016

Using isset() or array_key_exists should be make no difference here. The only difference is that array_key_exists return false if the value is null where isset() will return true.

Please add a trace log and your controller logic for debugging

@battle-mage
Copy link
Author

battle-mage commented Oct 31, 2016

Exception with stack trace

"name":"PHP Notice",
"message":"Undefined offset: 1",
"code":8,
"type":"yii\\base\\ErrorException",
"file":"/var/project/yii2backend/vendor/linslin/yii2-curl/Curl.php",
"line":405,
"stack-trace":[
"#0 /var/project/yii2backend/vendor/linslin/yii2-curl/Curl.php(405): yii\\base\\ErrorHandler->handleError(8, 'Undefined offse...', '/var/project/yi...', 405, Array)",
"#1 /var/project/yii2backend/vendor/linslin/yii2-curl/Curl.php(374): linslin\\yii2\\curl\\Curl->_extractAdditionalCurlParameter()",
"#2 /var/project/yii2backend/vendor/linslin/yii2-curl/Curl.php(129): linslin\\yii2\\curl\\Curl->_httpRequest('POST', 'https://domain....', false)",
"#3 /var/project/yii2backend/components/user/UserNotificationServiceImpl.php(49): linslin\\yii2\\curl\\Curl->post('https://domain....', false)",
"#4 /var/project/yii2backend/components/user/UserNotificationServiceImpl.php(84): app\\components\\user\\UserNotificationServiceImpl->sendEmail('test@example....', '\\xD0\\xA0\\xD0\\xB5\\xD0\\xB3\\xD0\\xB8\\xD1\\x81\\xD1\\x82\\xD1\\x80\\xD0...', Array, 'registration_ge...')",
"#14 /var/project/yii2backend/web/index.php(39): yii\\base\\Application->run()",
"#15 {main}"
]

I found out that actually this row causes the exception:
list($this->responseType, $possible_charset) = explode(';', curl_getinfo($this->_curl, CURLINFO_CONTENT_TYPE));

Values of my variables at this moment:
$this->responseType = null
$possible_charset = undefined

Result of explode(';', curl_getinfo($this->_curl, CURLINFO_CONTENT_TYPE)):
array(1) { [0]=> string(16) "application/json" }

@linslin
Copy link
Owner

linslin commented Oct 31, 2016

Okey, the problem is a PHP notice due to list(). Could you checkout the dev branch and check if its gone? If so i would release v1.0.10.

linslin added a commit that referenced this issue Oct 31, 2016
@battle-mage
Copy link
Author

battle-mage commented Oct 31, 2016

Yes, dev 1.0.10 seem to be working fine.
The reason of problem is that I had only one header, while list() expected at least two elements?

@linslin
Copy link
Owner

linslin commented Oct 31, 2016

Yea, list() comes with a lot of funny stuff http://php.net/manual/en/function.list.php. Version 1.0.10 is released. https://github.com/linslin/Yii2-Curl/releases/tag/1.0.10

Thank you.

@linslin linslin closed this as completed Oct 31, 2016
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

2 participants