JaquelineBrandao / yii

Automatically exported from code.google.com/p/yii
0 stars 0 forks source link

yiic shell, command model should not be case sensitive #743

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Assume a database table named "client" (no quotes)
2. Get a Yii install etc
3. Run protected/yiic shell
4. Type "model client" (note all lowercase), ignore warnings
5. Type "model Client" (note first letter uppercase)

What is the expected output? What do you see instead?
I'd expect an error OR the same output as when I would have typed "model 
Client" twice.

Not because of the capitalization issues of the database table, but because 
we now have two model files (client.php and Client.php) that both define 
the class User (PHP is assumed case insensitive). Thus, "model client" and 
"model Client" should be synonyms, and Yii should have a preference for 
first letter capitalizing class names. Thus, "model client" and "model Client" 
should both generate Client.php for class Client (not first letter caps).

What version of the product are you using? On what operating system?
yii 1.1, apache, ubuntu, php 5.2

Please provide any additional information below.

Original issue reported on code.google.com by dylan.verheul on 18 Dec 2009 at 10:42

GoogleCodeExporter commented 9 years ago
"PHP is assumed case insensitive"

This is not correct. PHP is inherently case-sensitive. 

If you have a table named "client" and you want a model named "client" 
generated, you
should use:

model client

If you have a table named "client" and you want a model named "Client" 
generated, you
should use:

model Client client

That is the proper way to use the model command.

Original comment by xx66...@gmail.com on 19 Dec 2009 at 7:15

GoogleCodeExporter commented 9 years ago
A small rephrasing: PHP is case insensitive when it comes to class names, and 
this 
will not change in the future. See http://bugs.php.net/bug.php?id=26575&edit=1

A simple test case.

<?php

class CaseSensitive {

}

class casesensitive {

}

?>

results in 

Fatal error: Cannot redeclare class casesensitive in test.php on line 7

Yii willfully generates identical class names, and thus willfully generates 
errors. Users 
should at least be notified of this, and preferably protected against this.

Original comment by dylan.verheul on 20 Dec 2009 at 7:13

GoogleCodeExporter commented 9 years ago
Addendum:

In http://www.yiiframework.com/doc/guide/database.ar the Yii documentation 
advises users to user all lowercase table and field names. Combined with the 
current 
(IMHO wrong) case handling of yiic shell, this will lead to users experiencing 
errors.

Quote:
Info: In this guide, we name columns using camel cases (e.g. createTime). This 
is 
because columns are accessed in the way as normal object properties which also 
uses camel-case naming. While using camel case does make our PHP code look more 
consistent in naming, it may introduce case-sensitivity problem for some DBMS. 
For 
example, PostgreSQL treats column names as case-insensitive by default, and we 
must quote a column in a query condition if the column contains mixed-case 
letters. 
For this reason, it may be wise to name columns (and also tables) only in 
lower-case 
letters (e.g. create_time) to avoid any potential case-sensitivity issues.

Original comment by dylan.verheul on 23 Dec 2009 at 6:47

GoogleCodeExporter commented 9 years ago
This problem is exacerbated when developing on Windows and deploying to Linux.
By default, mySQL on Windows forces table names to lowercase.

When deployed to Linux without modification, the models cannot find the 
appropriate
tables.

Original comment by site.sen...@gmail.com on 29 Jan 2010 at 10:30

GoogleCodeExporter commented 9 years ago

Original comment by qiang.xue on 31 Jan 2010 at 9:21

GoogleCodeExporter commented 9 years ago
Will leave it as is. Yii requires class file names to be the same as the class 
name
(case-sensitive on *nix systems) if auto-loading is needed. The syntax of model
command is: model ClassName [table-name]. For this reason, you should be careful
about the case of the class name.

Original comment by qiang.xue on 1 Feb 2010 at 10:41

GoogleCodeExporter commented 9 years ago
Polite request to reconsider.

1) PHP is a multi-platform language. Some PHP platform OS's do not support case 
sensitivity in file names.

2) PHP file names may be case sensitive on SOME *nix systems, but the class 
name 
casing in PHP is purely cosmetic (see my comment #2 above).

3) (Combining 1 and 2) Depending on file case names means Yii would support 
user.php and User.php as separate files containing separate classes user and 
User, 
which PHP would not allow.

The logical step for Yii would be to realize the above, and fix it (or at least 
deprecate 
the file name case sensitivity and make yiic shell act smarter).

Original comment by dylan.verheul on 3 Feb 2010 at 6:05

GoogleCodeExporter commented 9 years ago
The problem is when you run "model user", should Yii generate "user.php" or
"User.php"? Not all people like being forced to use Camel case in their class 
names.

Original comment by qiang.xue on 3 Feb 2010 at 1:29

GoogleCodeExporter commented 9 years ago
The current model command works well. MHO is that it does not need changing as 
you 
will get the results you desire if you understand and use it correctly.

Original comment by wapr...@gmail.com on 3 Feb 2010 at 2:24

GoogleCodeExporter commented 9 years ago
to be precise..
PostgreSQL does not treat column (or any) names as case-insensitive.
it's client library does fold unquoted names/identifiers to lowercase.
hth.

Original comment by aa.del...@yahoo.com on 13 Jul 2010 at 6:27