Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fixing "Undefined offset" error in ReflectionMethod::isEmpty() #102

Merged
merged 1 commit into from

3 participants

@iteman

Since the path element is not always the second element of the array, an error Undefined offset: 2 will be raised in the ReflectionMethod::isEmpty() method.

@MarcelloDuarte

@iteman does that actually fixes the issue? I see the new line character being used "\n" in your fix. Since you are on it can you please replace the "\n" with PHP_EOL and re-submit? thanks.

@iteman

The \n has existed since f9ed1b6.

Since \n is always linefeed (LF, 0x0a) and the return value of ReflectionMethod::__toString() is always concatenated with linefeed regardless of platform, this code will work on any platform. And PHP_EOL will not work on Windows and Mac.

@MarcelloDuarte

@iteman ok...
@adrianmoya can you please check @iteman PR for us under Windows? thanks both.

@adrianmoya

@iteman @MarcelloDuarte sure, is there a specific test you want me to try? under what condition the error was rised?

@MarcelloDuarte

@adrianmoya try leave an example empty. This is the use case in which this reflection call happens. Thanks.

@adrianmoya

@MarcelloDuarte Leaving an example empty doesn't fail in the current stable version (1.4.2.) on windows. Any other case that could trigger this error?

@MarcelloDuarte

@iteman can you please provide an example of a case where this error is produced? Whatever context you can give is much appreciated. Thanks.

@iteman

@adrianmoya @MarcelloDuarte Any PHPDoc tag will produce this error as the following:

    /**
     * @since Method available since Release 3.0.0
     */
    public function itShouldFail()
    {
        $this->spec(false)->should->beTrue();
    }
@adrianmoya

Ok, I was able to reproduce the error in windows, and the fix works fine.

@MarcelloDuarte

Thanks all!

@MarcelloDuarte MarcelloDuarte merged commit cb54c94 into phpspec:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 27, 2012
  1. @iteman

    Fixed a defect that caused an error "Undefined offset: 2" to be raise…

    iteman authored
    …d in the ReflectionMethod::isEmpty() method.
This page is out of date. Refresh to see the latest.
Showing with 2 additions and 2 deletions.
  1. +2 −2 src/PHPSpec/Util/ReflectionMethod.php
View
4 src/PHPSpec/Util/ReflectionMethod.php
@@ -68,8 +68,8 @@ public function isEmpty()
$this->_objectOrClassName,
$this->_methodName
);
- list(,$path,) = explode("\n", (string)$method);
- preg_match('/(@@ )(.*\.php)( )(\d+)(\D*)(\d+)/', $path, $matches);
+ $methodString = explode("\n", (string)$method);
+ preg_match('/(@@ )(.*\.php)( )(\d+)(\D*)(\d+)/', $methodString[ count($methodString) - 3 ], $matches);
list ($path, $start, $end) = array(
$matches[2], $matches[4], $matches[6]
);
Something went wrong with that request. Please try again.