Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Check if a variable is set with the php function isset($var). #29

Closed
wants to merge 7 commits into from

2 participants

David Daester Sam Bisbee
David Daester

Because the stdClass is dynamic, a variable can be avialbe, but must not be. Insteand of just checking if aviable (by accessing it) it's much more better to aks if the variable is realy set. Why? In development mode on php, you will get thousends of warnings (ok, there are 4) that a var is not set in this content.
So the parser can easier check itself (bool-check) than type-check to null.

and others added some commits
Sam Bisbee Fixing a typo bug (closes #26)
Apparently I was trying to throw a concept of a class instead of an
instantiation. Nice.
4a60747
Sam Bisbee Fixing HTTP/1.1 decoding for _changes. (closes #27) eb7d8e0
Sam Bisbee Merge branch 'master' into v0.6.x a76b203
Sam Bisbee CHANELOG entry for Yo-han's patch. f5fdbac
David Daester Swissbite Check if a variable is set with the php function isset($var).
Because the stdClass is dynamic, a variable can be avialbe, but must not be. Insteand of just checking if aviable (by accessing it) it's much more better to aks if the variable is realy set. Why? In development mode on php, you will get thousends of warnings (ok, there are 4) that a var is not set in this content.
So the parser can easier check itself (bool-check) than type-check to null.
fa47283
David Daester

Because of the followed notices I changed the variable and index lookup. I didn't go trough the code in every detail, just in the notices below.

Notice: Undefined variable: response in [..]/sag/src/Sag.php on line 205

Notice: Undefined index: Cookie in [..]/sag/src/Sag.php on line 941

Notice: Undefined property: stdClass::$Transfer-Encoding in [..]//sag/src/Sag.php on line 1111

Notice: Undefined property: stdClass::$Connection in [..]//sag/src/Sag.php on line 1176

Notice: Undefined variable: response in [..]/sag/src/Sag.php on line 205

Notice: Undefined index: Cookie in [..]/sag/src/Sag.php on line 941

Notice: Undefined property: stdClass::$Connection in [..]/sag/src/Sag.php on line 1176

David Daester Swissbite closed this
David Daester Swissbite reopened this
David Daester

damit, wrong button. Sorry

Sam Bisbee
Owner

Hi Swissbite,

First off, thank you for your patches. It's always great to see community contribution!

I tested your changes to see if there is a performance improvement. The test suite (make check) actually ran 1 second faster without your changes. I'm sure that if I ran both code sets enough times they would average out to the same execution time.

So since Sag does not support strict mode, which is what your patches are really about, and there is no performance gain, I am not going to merge your pull request in.

However, there is plenty more work to be done on Sag. Let me know if you are interested in contributing elsewhere - help is always appreciated! :)

Cheers,
Sam

Sam Bisbee sbisbee closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 11, 2011
  1. Fixing a typo bug (closes #26)

    authored
    Apparently I was trying to throw a concept of a class instead of an
    instantiation. Nice.
Commits on Sep 16, 2011
Commits on Oct 8, 2011
  1. David Daester

    Check if a variable is set with the php function isset($var).

    Swissbite authored
    Because the stdClass is dynamic, a variable can be avialbe, but must not be. Insteand of just checking if aviable (by accessing it) it's much more better to aks if the variable is realy set. Why? In development mode on php, you will get thousends of warnings (ok, there are 4) that a var is not set in this content.
    So the parser can easier check itself (bool-check) than type-check to null.
Commits on Oct 9, 2011
  1. David Daester

    Var check over isset

    Swissbite authored
  2. David Daester
This page is out of date. Refresh to see the latest.
Showing with 37 additions and 19 deletions.
  1. +18 −0 CHANGELOG
  2. +19 −19 src/Sag.php
18 CHANGELOG
View
@@ -1,6 +1,24 @@
Sag Changes
===========
+Version 0.6.1
+-------------
+
+Fixed Bugs
+
+ * Fixed a typo bug where I was trying to throw the concept of an Exception
+ instead of an instantiation. Luckily it is rare for this corner case in the
+ code to run. Thanks to Oliver Kurowski (github/a4mc) for reporting.
+ (closes #26)
+
+ * Fixed a problem with the HTTP/1.1 decoding of chunked message bodies that
+ was causing continuous change feed requests (/db/_changes?continuous=true)
+ to fail. (closes #27)
+
+ * Fixed a typo bug in examples/phpSessions, changed createdOn to createdAt.
+ Thanks to Yo-Han (github/yo-han) for finding the bug and submitting the
+ patch as a pull request. (closes #28)
+
Version 0.6.0
-------------
38 src/Sag.php
View
@@ -202,7 +202,7 @@ public function get($url) {
* Not caching, or we are caching but there's nothing cached yet, or our
* cached item is no longer good.
*/
- if(!$response) {
+ if(!isset($response)) {
$response = $this->procPacket('GET', $url);
}
@@ -938,7 +938,7 @@ private function procPacket($method, $url, $data = null, $headers = array()) {
* Checking this again because $headers['Cookie'] could be set in two
* different logic paths above.
*/
- if($headers['Cookie']) {
+ if(isset($headers['Cookie'])) {
$buff = '';
foreach($headers['Cookie'] as $k => $v) {
@@ -1001,7 +1001,7 @@ private function procPacket($method, $url, $data = null, $headers = array()) {
//some PHP configurations don't throw when fsockopen() fails
if(!$sock) {
- throw Exception($sockErrStr, $sockErrNo);
+ throw new Exception($sockErrStr, $sockErrNo);
}
}
catch(Exception $e) {
@@ -1076,7 +1076,7 @@ private function procPacket($method, $url, $data = null, $headers = array()) {
* Don't parse empty lines before the initial header as being the
* header/body delim line.
*/
- if($response->headers->_HTTP->raw) {
+ if(isset($response->headers->_HTTP->raw)) {
$isHeader = false; //the delim blank line
}
}
@@ -1108,7 +1108,7 @@ private function procPacket($method, $url, $data = null, $headers = array()) {
}
}
}
- else if($response->headers->{'Transfer-Encoding'}) {
+ else if(isset($response->headers->{'Transfer-Encoding'})) {
/*
* Parse the response's body, which is being sent in chunks. Welcome to
* HTTP/1.1 land.
@@ -1119,15 +1119,23 @@ private function procPacket($method, $url, $data = null, $headers = array()) {
*/
if($chunkSize === null) {
//Look for a chunk size
- $chunkSize = hexdec(rtrim($line));
+ $line = rtrim($line);
- if(!is_int($chunkSize)) {
- throw new SagException('Invalid chunk size: '.$line);
+ if(!empty($line) || $line == "0") {
+ $chunkSize = hexdec($line);
+
+ if(!is_int($chunkSize)) {
+ throw new SagException('Invalid chunk size: '.$line);
+ }
}
}
+ else if($chunkSize === 0) {
+ // We are done processing all the chunks.
+ $chunkParsingDone = true;
+ }
else if($chunkSize) {
//We have a chunk size, so look for data
- if(strlen($line) > $chunkSize) {
+ if(strlen($line) > $chunkSize && strlen($line) - 2 > $chunkSize) {
throw new SagException('Unexpectedly large chunk on this line.');
}
else {
@@ -1142,11 +1150,7 @@ private function procPacket($method, $url, $data = null, $headers = array()) {
*/
$chunkSize -= strlen($line);
- if($chunkSize > 0) {
- //Do not count the CRLF if not the end of the chunk.
- $chunkSize += ($numCRLFs * 2);
- }
- else {
+ if($chunkSize <= 0) {
/*
* Nothing left to this chunk, so the next link is going to be
* another chunk size. Or so we hope.
@@ -1155,10 +1159,6 @@ private function procPacket($method, $url, $data = null, $headers = array()) {
}
}
}
- else if($chunkSize === 0) {
- // We are done processing all the chunks.
- $chunkParsingDone = true;
- }
else {
throw new SagException('Unexpected empty line.');
}
@@ -1173,7 +1173,7 @@ private function procPacket($method, $url, $data = null, $headers = array()) {
}
// HTTP/1.1 assumes persisted connections, but proxies might close them.
- if(strtolower($response->headers->Connection) != 'close') {
+ if(!isset($response->headers->Connection)|| strtolower($response->headers->Connection) != 'close') {
$this->connPool[] = $sock;
}
Something went wrong with that request. Please try again.