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

Method with same name already defined in this class #703

Closed
realmarkcross opened this issue Sep 9, 2018 · 32 comments
Closed

Method with same name already defined in this class #703

realmarkcross opened this issue Sep 9, 2018 · 32 comments
Labels

Comments

@realmarkcross
Copy link

L5.7.2, LIDEH:2.5.1
_ide_helper.php produces error in PHPStorm : 'Method with same name already defined in this class'
on many methods. Never had an issue with 5.6, but this is the first time I'm installing both 5.7 Laravel and 2.5.1 LIDEH.
Screenshot shows the first part of the file with underlined methods that reflect this error.
image

@guice
Copy link

guice commented Sep 10, 2018

+1 on this. I can't here with this same issue.

Laravel 5.7
PhpStorm 2018.2.2 (not really relevant, this is a php code error, not an IDE Bug)

@yutarux
Copy link

yutarux commented Sep 11, 2018

Me, three.

Laravel 5.5
Intellij IDEA Ultimate 2018.2.3
ide-helper 2.5.0

@yutarux
Copy link

yutarux commented Sep 11, 2018

Same as #697 ?

@guice
Copy link

guice commented Sep 11, 2018

@yutarux No. Our files create successfully. We don't get an error during compose update. Our error is within PhpStorm, complaining about pre-existing methods.

@Evrimedont
Copy link

+1

Laravel 5.7
PHPStorm 2018.2.3
ide-helper 2.5.1

1 similar comment
@SeagleDub
Copy link

+1

Laravel 5.7
PHPStorm 2018.2.3
ide-helper 2.5.1

@gugglegum
Copy link

The same issue happened after updating ide-helper from 2.4.3 to 2.5.1. In 2.4.3 all was OK. Any suggestions?

@tnorthcutt
Copy link
Contributor

tnorthcutt commented Sep 14, 2018

Another one here; confirmed that reverting to 2.4.3 fixed it. Not sure what the issue is yet, but here are the commits since 2.4.3.

Edit:
Doing some manual git blame-type work here. As of this commit the bug is present. Will update if I narrow it down more.

Edit 2:
Bug not present at 09610da

Edit 3:
Bug present at bbd96d3

Edit 4:
Bug present at 4691bc5fbdcebc6a1ae0fe865292

Edit 5:
Bug present at d961482

@tnorthcutt
Copy link
Contributor

Update: the bug appears to be introduced in this commit: b644e48

/cc @barryvdh

@guyaloni
Copy link

guyaloni commented Oct 3, 2018

+1

Laravel 5.7.6
PHPStorm 2017.3.6

@hcancelik
Copy link

+1

Laravel 5.7.9
PHPStorm 2018.2.5

@ghost
Copy link

ghost commented Oct 21, 2018

+1

Laravel 5.7.6
PHPStorm 2017.3.6

@JeppeKnockaert
Copy link
Contributor

I've proposed a fix for this issue in #720.

@ghost
Copy link

ghost commented Oct 23, 2018

I've proposed a fix for this issue in #720.

Please explain step by step how to solve this problem...
Grateful...

@JeppeKnockaert
Copy link
Contributor

The issue is that methods are both defined in the classes defined in idehelper, as well as in the class docblock.

For example, take this snippet from the idehelper file for the DB class:

    /**
     * 
     *
     * @method static \Illuminate\Database\ConnectionInterface connection(string $name = null)
     * @method static string getDefaultConnection()
     * @method static void setDefaultConnection(string $name)
     * @method static \Illuminate\Database\Query\Builder table(string $table)
     * @method static \Illuminate\Database\Query\Expression raw($value)
     * @method static mixed selectOne(string $query, array $bindings = [])
     * @method static array select(string $query, array $bindings = [])
     * @method static bool insert(string $query, array $bindings = [])
     * @method static int update(string $query, array $bindings = [])
     * @method static int delete(string $query, array $bindings = [])
     * @method static bool statement(string $query, array $bindings = [])
     * @method static int affectingStatement(string $query, array $bindings = [])
     * @method static bool unprepared(string $query)
     * @method static array prepareBindings(array $bindings)
     * @method static mixed transaction(\Closure $callback, int $attempts = 1)
     * @method static void beginTransaction()
     * @method static void commit()
     * @method static void rollBack()
     * @method static int transactionLevel()
     * @method static array pretend(\Closure $callback)
     * @see \Illuminate\Database\DatabaseManager
     * @see \Illuminate\Database\Connection
     */ 
    class DB {
        
        /**
         * Get a database connection instance.
         *
         * @param string $name
         * @return \Illuminate\Database\Connection 
         * @static 
         */ 
        public static function connection($name = null)
        {
            return \Illuminate\Database\DatabaseManager::connection($name);
        }

You see there's both a method connection and an @method tag for the connection method in the docblock.

Some versions of PhpStorm (e.g. 2018.3) give an error on this kind of thing: "Method with the same name already defined in this class", causing PhpStorm to ignore the method completely.

In my pull request I detect the @method tags for which a real method already exists and leave them out of the docblock, so they wouldn't cause any issues.

When/if the fix gets released, you will just need to update idehelper to the newest version and run php artisan ide-helper:generate again to solve the issue.

@ghost
Copy link

ghost commented Oct 24, 2018

The issue is that methods are both defined in the classes defined in idehelper, as well as in the class docblock.

For example, take this snippet from the idehelper file for the DB class:

    /**
     * 
     *
     * @method static \Illuminate\Database\ConnectionInterface connection(string $name = null)
     * @method static string getDefaultConnection()
     * @method static void setDefaultConnection(string $name)
     * @method static \Illuminate\Database\Query\Builder table(string $table)
     * @method static \Illuminate\Database\Query\Expression raw($value)
     * @method static mixed selectOne(string $query, array $bindings = [])
     * @method static array select(string $query, array $bindings = [])
     * @method static bool insert(string $query, array $bindings = [])
     * @method static int update(string $query, array $bindings = [])
     * @method static int delete(string $query, array $bindings = [])
     * @method static bool statement(string $query, array $bindings = [])
     * @method static int affectingStatement(string $query, array $bindings = [])
     * @method static bool unprepared(string $query)
     * @method static array prepareBindings(array $bindings)
     * @method static mixed transaction(\Closure $callback, int $attempts = 1)
     * @method static void beginTransaction()
     * @method static void commit()
     * @method static void rollBack()
     * @method static int transactionLevel()
     * @method static array pretend(\Closure $callback)
     * @see \Illuminate\Database\DatabaseManager
     * @see \Illuminate\Database\Connection
     */ 
    class DB {
        
        /**
         * Get a database connection instance.
         *
         * @param string $name
         * @return \Illuminate\Database\Connection 
         * @static 
         */ 
        public static function connection($name = null)
        {
            return \Illuminate\Database\DatabaseManager::connection($name);
        }

You see there's both a method connection and an @method tag for the connection method in the docblock.

Some versions of PhpStorm (e.g. 2018.3) give an error on this kind of thing: "Method with the same name already defined in this class", causing PhpStorm to ignore the method completely.

In my pull request I detect the @method tags for which a real method already exists and leave them out of the docblock, so they wouldn't cause any issues.

When/if the fix gets released, you will just need to update idehelper to the newest version and run php artisan ide-helper:generate again to solve the issue.

Thank you)

@fmonts
Copy link

fmonts commented Jan 3, 2019

Is the issue fixed? I never worked in Laravel (I work in Symfony where there is a plugin installed in the IDE, much simpler than this...) and I have to do something on a project started by someone else...

I generate this _ide_helper.php file following the PHPStorm instructions here, but if I open it it's full of IDE errors and warnings... For example the class App has a duplicate declaration both here and in vendor\laravel...\Illuminate\Support\Facades\App

What should I do to fix the issue? Ignore a vendor folder? This is very weird...

@Mapteg34
Copy link

Mapteg34 commented Jan 9, 2019

+1
Laravel 5.7.14
PHPStorm 2018.3.2

@martinresko
Copy link

+1
Lumen (5.7.1) (Laravel Components 5.7.*)
PHPStorm 2018.3.3

@pks1989
Copy link

pks1989 commented May 11, 2019

Аs mentioned earlier, it is PHPStorm IDE problem, because IDE ispections take into account declaration in _ide_helper.php.
So... i mark this file as plain text, and problem gone :)

Screenshot_20190511_163647

@gugglegum
Copy link

@pks1989 Bad solution. If you mark _ide_helper.php as Plain Text you got the same result as removing this (barryvdh/laravel-ide-helper) package at all.

@pks1989
Copy link

pks1989 commented May 11, 2019

@pks1989 Bad solution. If you mark _ide_helper.php as Plain Text you got the same result as removing this (barryvdh/laravel-ide-helper) package at all.

ok, my fault.

@stale
Copy link

stale bot commented Jul 29, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If this issue is still present on the latest version of this library on supported Laravel versions, please let us know by replying to this issue so we can investigate further.
Thank you for your contribution! Apologies for any delayed response on our side.

@stale stale bot added the stale label Jul 29, 2020
@stale stale bot closed this as completed Sep 27, 2020
@ahait
Copy link

ahait commented Sep 13, 2021

This should not be closed since it's still an issue.

@olezhkafp
Copy link

I have the same with laravel v9.35.1 and phpstorm 2022.2.1

@JohnnyWalkerDigital
Copy link

Laravel 9.43 and PHPStorm 2202.2.3

Is there a harmless way to get the IDE to ignore this (assuming it's not actually a problem?).

@itsserbin
Copy link

+1
Laravel 10.8

@stehled
Copy link

stehled commented Nov 7, 2023

+1 Symfony

@Enterprize-1701
Copy link

+1
Laravel 10.10

@barryvdh
Copy link
Owner

barryvdh commented Nov 8, 2023

This issue is already closed. Is something changed? Which PR should I look at?

@Enterprize-1701
Copy link

Enterprize-1701 commented Nov 8, 2023

When i use "barryvdh/laravel-dompdf": "^2.0", in my project in laravell 10.10 I face with this again.
"Another definition with same name exists in this file" for _ide_helper.php in PhpStorm 2023.2.3.

@efren-corillo
Copy link

@Enterprize-1701

When i use "barryvdh/laravel-dompdf": "^2.0", in my project in laravell 10.10 I face with this again. "Another definition with same name exists in this file" for _ide_helper.php in PhpStorm 2023.2.3.

It's 2024 and Still getting this issue. I manually removed the duplicate DomPdf "PDF" vs "pdf", but when doing composer install or update the _ide_helper.php is regenerated and the issue comes back.

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