nette / php-generator

🐘 Generates neat PHP code for you. Supports new PHP 8.3 features.
https://doc.nette.org/php-generator
Other
2.11k stars 138 forks source link

"Uses" and "Extend" #26

Closed carono closed 7 years ago

carono commented 7 years ago

Description

When you specify "uses", the class is not inherited correctly from the specified class, if they are partially matched and there is a difference in the registers.

Steps To Reproduce

$namespace = new PhpNamespace('app\models');
$namespace->addUse('Yii');
$class = $namespace->addClass('Demo');
$class->addExtend('yii\db\ActiveRecord');
echo "<?php\n\n".$namespace;
<?php

namespace app\models;

use Yii;

class Demo extends Yii\db\ActiveRecord // <= Wrong namespace, expected yii\db\ActiveRecord
{
}
dg commented 7 years ago

Both yii\db\ActiveRecord and Yii\db\ActiveRecord will be resolved to Yii\db\ActiveRecord, or not? I.e. there is no difference.

https://3v4l.org/HkpSm -> Fatal error: Class 'Yii\db\ActiveRecord' not found

carono commented 7 years ago

I expect the class to be yii\db\ActiveRecord, because it has nothing to do with the previously specified Yii and I specify this class directly in $class->addExtend('yii\db\ActiveRecord');. In this case, yii\db\ActiveRecord and Yii\db\ActiveRecord this is not the same thing.

dg commented 7 years ago

Look at this example https://3v4l.org/HkpSm, they are the same because PHP is case insensitive.

carono commented 7 years ago

Yes, I looked at the demo more closely, indeed, this is normal behavior, for me it's unexpected, I'm sorry for the trouble.