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

Adding use Yii; in the beginning of migration kills console #8206

Closed
mrfatguy opened this issue Apr 27, 2015 · 18 comments
Closed

Adding use Yii; in the beginning of migration kills console #8206

mrfatguy opened this issue Apr 27, 2015 · 18 comments
Assignees
Labels
status:to be verified Needs to be reproduced and validated.

Comments

@mrfatguy
Copy link

To my extreme surprise, adding use Yii; in the beginning of migration file kills command-line (Git for Windows) very badly.

I think you may consider working-around this somehow.

I know, that Yii is available in migration and one does not / must not add use Yii; in the beginning of migration file. But, I'm pretty sure, you'd like to handle this situation a bit more gently, instead of firing user command-line console into one-way Mars mission, right? :>

@samdark samdark added the status:to be verified Needs to be reproduced and validated. label Apr 27, 2015
@samdark samdark added this to the 2.0.5 milestone Apr 27, 2015
@cebe
Copy link
Member

cebe commented Apr 27, 2015

what is the error you see? can you paste an example on how you added this? Do you have any php extensions installed like apc for example?

@mrfatguy
Copy link
Author

This is the migration code:

<?php

use Yii;
use yii\db\Schema;
use yii\db\Migration;

class m150427_130904_test extends Migration
{
    public function up()
    {

    }

    public function down()
    {

    }
}

and this is the effect of running it (Polish Windows, but you get the picture, right?):

bummer

And this is my php.ini's part with extensions:

extension=php_bz2.dll
extension=php_curl.dll
extension=php_mbstring.dll
extension=php_exif.dll
extension=php_fileinfo.dll
extension=php_gd2.dll
extension=php_gettext.dll
;extension=php_gmp.dll
;extension=php_intl.dll
;extension=php_imap.dll
;extension=php_interbase.dll
;extension=php_ldap.dll
;extension=php_mssql.dll
;extension=php_mbstring.dll
;extension=php_exif.dll      ; Must be after mbstring as it depends on it
extension=php_mysql.dll
extension=php_mysqli.dll
;extension=php_oci8.dll      ; Use with Oracle 10gR2 Instant Client
;extension=php_oci8_11g.dll  ; Use with Oracle 11gR2 Instant Client
extension=php_openssl.dll
;extension=php_pdo_firebird.dll
extension=php_pdo_mysql.dll
;extension=php_pdo_oci.dll
;extension=php_pdo_odbc.dll
;extension=php_pdo_pgsql.dll
extension=php_pdo_sqlite.dll
;extension=php_pdo_sqlite_external.dll
;extension=php_pgsql.dll
;extension=php_pspell.dll
;extension=php_shmop.dll

; The MIBS data available in the PHP distribution must be installed. 
; See http://www.php.net/manual/en/snmp.installation.php 
;extension=php_snmp.dll

extension=php_soap.dll
extension=php_sockets.dll
extension=php_sqlite3.dll
;extension=php_sybase_ct.dll
;extension=php_tidy.dll
extension=php_xmlrpc.dll
extension=php_xsl.dll

No APC or other cache, no magic, no nothing. Just an old, bit modified XAMPP running on Windows 7.

@samdark samdark self-assigned this Apr 27, 2015
@samdark
Copy link
Member

samdark commented Apr 27, 2015

I'll try reproducing it.

@mrfatguy
Copy link
Author

Go ahead. Just added my list of extensions. Can provide you (zipped file, FTP link) with entire XAMPP package, I'm using, if you wish. Hope, this is something local, happening just for me, and not the general problem for all.

@mdmunir
Copy link
Contributor

mdmunir commented Apr 27, 2015

PHP Warning 'yii\base\ErrorException' with message 'The use statement with non-compound name 'Yii' has no effect'

IMO, its not yii bug, but php error. You cannot declare 2 class with same name.

@mrfatguy
Copy link
Author

Fine. But, I'm not talking, that this is Yii bug. This issue is about handling this gracefully. If we are required to manually add use Yii; to every class, where we want to use it, because it is not declared there automatically, then IMHO the same logic should be used in migrations.

In other words -- what is the reason for auto-declaring Yii class for migrations, if it is not auto-declared for other classes AFAIK (or maybe I'm missing something bloody obvious?).

@mdmunir
Copy link
Contributor

mdmunir commented Apr 27, 2015

what is the reason for auto-declaring Yii class in migrations

Please, explain your question. i dont get it.

there is my generated migration. no use Yii; line.

<?php

use yii\db\Schema;
use yii\db\Migration;

class m150427_131430_dont_do_anything extends Migration
{
    public function up()
    {

    }

    public function down()
    {
        echo "m150427_131430_dont_do_anything cannot be reverted.\n";

        return false;
    }

    /*
    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
    }

    public function safeDown()
    {
    }
    */
}

@klimov-paul
Copy link
Member

Migration classes are NOT under any namespace, thus using classes from global namespace does not require 'use' statement.

@cebe cebe removed this from the 2.0.5 milestone Apr 27, 2015
@mrfatguy
Copy link
Author

@klimov-paul OK, fine... But, then again... No matter, what is causing this problem, I can't imagine any professional framework that causes command-line to blow if user do anything.

I reported this problem not to seek your explanation, what is causing this problem (but thank you, for explaining this to me), but to point you out, that you should at least consider, if there is any workaround for this? I know, that tracing or fixing this "problem" can't be beyond anything, you can do, but... then again, Yii2 is a professional framework and in a professional framework such extremely bad looking hangups shouldn't happen in any conditions.

@klimov-paul
Copy link
Member

causes command-line to blow if user do anything

PHP parse errors and warnings are out of the framework scope I am afraid.

there is any workaround for this?

Are asking a wolkaround for PHP fatal error? I don't know any, sorry.

such extremely bad looking hangups shouldn't happen in any conditions.

So if, for example, you miss a semicolon at the end of the statement or haven't enclose brackets correctly - framework should handle it somehow? Provide you a walk around? Are you serious?

Or there is something else I have missed?

@cebe
Copy link
Member

cebe commented Apr 27, 2015

@trejder yii has an errorhandler to deal with such errors, if your php crashes in some way this is a bug in php and yii can not do anything to fix this, this is another level.

@samdark
Copy link
Member

samdark commented Apr 27, 2015

I think the best thing to do in this case is to trace down error to minimal example and submit it as PHP bug. Of course, if you have time for it since it doesn't sound like easy debug session.

@mrfatguy
Copy link
Author

@klimov-paul Yes, I'm pretty serious. Please, don't make an equation between forgetting about missing semicolon and situation, when I should not declare Yii because it is already declared. Especially, when in all other classes that I use in framework, I should declare it! First is quite obvious -- anyone knows, that semicolon is required at the end of each line and nearly every good IDE can trace this down. Second is not so obvious at all and no IDE can trace it down. You're making two completely different situations looking like it would be similar.

@cebe I'm not sure, that Yii's error handler can trace redeclaration of class and deal with that in case of migration. If so, why then the console blows away on such obvious thing?

@samdark This is neither PHP nor Yii bug. This is just a very special situation, where migrations are run in global namespace and thus does not require declaring Yii, while all other classes and pieces of application are not run in global namespace and therefore requires such declaration.

All of you seems to be doing a really big problem out of something really small. In my opinion, a workaround, I'm asking for is to update migrate command's code, so it would insert simple comment to the beginning of each auto-generated migration:

Keep in mind, that all migrations are run in global namespace and thus you shouldn't declare Yii here. It is already declared in global namespace and redeclaring it may give an unpredictable results.

This would "solve" the problem once and for all. Even those programmer, like me, for which -- against to what @klimov-paul says -- this situation isn't obvious, would be informed about possible danger of redeclaring Yii class inside migration.

I have a very bad feeling, that you're, again and again, keep forgetting that Yii2 users are not always so experienced as you are and not always posses such knowledge as you are. For you, the fact that migrations are run in global namespace, is pretty obvious. For me it wasn't. And due to lack of above proposed comment and due to lack of my knowledge I wasted over half an hour on tracing what is going on and why my console gets fired hell?

@mdmunir
Copy link
Contributor

mdmunir commented Apr 28, 2015

Just switch off debug mode.

would be informed about possible danger of redeclaring Yii class inside migration.

Not only in migration file, also in view file and all file that not using namespace. Not only Yii class. but also all global class e.g. PDO, ReflectionClass, Exception, etc, etc.

@samdark
Copy link
Member

samdark commented Apr 28, 2015

@trejder PHP crashes so it's PHP bug. Normally it should have produce a fatal error which is handled well by Yii.

@samdark
Copy link
Member

samdark commented Apr 28, 2015

Just checked it. It's not even PHP bug, it's your environment. That's what I have on Windows:

Console error

@mrfatguy
Copy link
Author

mrfatguy commented May 4, 2015

Everything you have shown so far seems proving, that this is my local problem only. However, I found it hard to believe. Mainly because:

  • I haven't changed anything in my XAMPP structure, php.ini content etc. for past many, many months, I'm actually still using old-good 1.8.1 version of XAMPP (versioned without compliance to PHP version),
  • all metioned problems started about month ago, when I started coding in Yii2 and happens only in Yii2-powered apps -- I can't reproduce any of above mentioned problems in any of my Yii1-powered projects.

I have asked a Stack Overflow question on this matter -- in case someone would like to follow this.

@samdark
Copy link
Member

samdark commented May 4, 2015

Probably it's XAMPP problem and it should be updated since the bug could have been fixed already. If it's not, worth reporting to them. I'm not using XAMPP myself so can't confirm anything related to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:to be verified Needs to be reproduced and validated.
Projects
None yet
Development

No branches or pull requests

5 participants