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

Zend\Code\ClassScanner cannot scan abstract method when class has properties and other methods. #6893

Closed
alex-oleshkevich opened this issue Nov 18, 2014 · 4 comments
Assignees
Milestone

Comments

@alex-oleshkevich
Copy link

I have a class:

// does not work
namespace Project;

abstract class Config
{
    protected $config = array();

    public function getConfig()
    {
        return $this->config;
    }
    abstract public function getKey();
}

and the following code:

$scanner = new \Zend\Code\Scanner\DirectoryScanner('Project');
$method = $scanner->getClasses()[0]->getMethod('getKey');
var_dump($method->isAbstract());

Calling $method->isAbstract() results in "Fatal error: Uncaught exception 'Zend\Code\Exception\RuntimeException' with message 'No tokens were provided'".

This case is only when class has any property or method along with an abstract method. For example, if I remove "getConfig()" method and $config property - the code provided works fine.

// works
namespace Project;

abstract class Config
{
    abstract public function getKey();
}

I found a closed issue #2471 but the bug still exists in zf2.3.3 or dev-master.

demo: https://github.com/alex-oleshkevich/zend-class-scanner-bug

@alex-oleshkevich alex-oleshkevich changed the title Zend\Code\ClassScanner cannot scan abstract method. Zend\Code\ClassScanner cannot scan abstract method when class has properties and other methods. Nov 18, 2014
@Ocramius
Copy link
Member

Seems like @macnibblet wants to pick this up.

@macnibblet
Copy link
Contributor

@alex-oleshkevich Looking at the cause of the problem right now, it would seam the Zend\Code\Scanner\ClassScanner is failing to produce the end token for the method tokens segment.

@macnibblet
Copy link
Contributor

@alex-oleshkevich a temporary workaround until this is resolved is to not have the abstract methods last. Because that is when the parser seams to be freaking out.

<?php
// Works just fine
abstract class AbstractClass
{
    protected $config = array();

    abstract public function helloWorld();

    public function getConfig()
    {
        return $this->config;
    }
}

@Ocramius Ocramius self-assigned this Nov 19, 2014
@Ocramius Ocramius added this to the 2.3.4 milestone Nov 19, 2014
Ocramius pushed a commit that referenced this issue Nov 19, 2014
Ocramius added a commit that referenced this issue Nov 19, 2014
@Ocramius
Copy link
Member

Fixed in #6901

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

No branches or pull requests

3 participants