Expression is not allowed as field default value
You can not call a method to set a default value for a variable in PHP, not even if it is a static method. Change it to be set in the constructor:
use Yii;
class UserController extends XController
{
var $app;
function __construct() {
$this->app = Yii::app();
}
public function init()
{
$test = $this->app;
}
}
As a side note, you should not use the var
keyword in PHP versions > 4, see this question for an explanation. Expression is not allowed as field default value (on oop)
public $bdd = parent::conn();
You can't set property value from a function in the property declarationYou must initialize property value in methods, for example in constructor
class query extends connection
{
public $bdd;
public function __construct()
{
parent::__construct();
$this->bdd = parent::conn();
}
}
Expression is not allowed in a variable outside of a function
Move it into to the constructor (or any other function) - you seem not to have any constructor for the class, but __construct
will be called anyway :
protected $screenshotPath = '';
public function __construct() {
$this->$screenshotPath = __DIR__ . "/FailedTestsScreenshots";
}
or into SetUp()
:protected function SetUp() {
$this->$screenshotPath = __DIR__ . "/FailedTestsScreenshots";
$this->setBrowser( "*firefox" );
$this->SetBrowserUrl( $this->path );
}
How can I use an expression as parameter default value?
It's not possible, but if you're looking for more condensed solution in PHP 7 you can use new ??
operator:
echo $m ?? config('my.status.mode');
As alternative, you can create your own global Laravel helper, wrapper for config()
helper which will check variable for null and will return result from config:$m = default('status.mode', $m);
Helper can look like this:if (! function_exists('default')) {
function default($config, $value)
{
return is_null($value) ? config('my.'.$config) : $value;
}
}
An advantage of this method is you can add some functionality to this helper at any time. For example you could get config value translated to the current language without doing this in a controller or a model. Can I use a function for a default value in MySql?
No, you can't.
However, you could easily create a trigger to do this, such as:
CREATE TRIGGER before_insert_app_users
BEFORE INSERT ON app_users
FOR EACH ROW
SET new.api_key = uuid();
Related Topics
How to Insert JSON Array into MySQL Database
How to Check Is Timezone Identifier Valid from Code
How to Get Products from a Particular Category in Magento Ecommerce
Converting JSON to CSV Format Using PHP
PHP Class: Global Variable as Property in Class
Which PHP Mcrypt Cipher Is Safest
Calling a PHP Function from an HTML Form in the Same File
Difference Between Buffered and Unbuffered Queries
Disable Doctrine 2 Lazy Loading When Using Jms Serializer
Add Some Attribute Values to Woocommerce Variable Product Title from Chosen Variation
Docx File Type in PHP Finfo_File Is Application/Zip
Login Event Handling in Laravel 5
Remove Namespace from Xml Using PHP
Upgrading Laravel 5.5 to 5.6 Error