yiisoft / view

Yii view rendering library
https://www.yiiframework.com/
BSD 3-Clause "New" or "Revised" License
56 stars 44 forks source link

Add default value to BaseView::getCommonParameter() #177

Closed vjik closed 3 years ago

vjik commented 3 years ago

For example:

// throws InvalidArgumentException
$view->getCommonParameter('non-exists-parameter');

// return 42
$view->getCommonParameter('non-exists-parameter', 42);
terabytesoftw commented 3 years ago

What would be the use case, for me it doesn't make sense to pass a value in a get(), it looks like a hack ?

vjik commented 3 years ago

What would be the use case, for me it doesn't make sense to pass a value in a get(), it looks like a hack ?

Use case: https://github.com/yiisoft/yii-widgets/pull/36/files#diff-9af7cbc9482b96d8d6612ce55840fd1338c88716c03623d2c46ab514d3aac9d2R50

samdark commented 3 years ago

We can use $view->getCommonParameter('non-exists-parameter') ?? 42 but it won't really do isset so it won't be possible to store null as parameter value. I think for such use-cases it's useful.