I'm doing something wrong and I can't figure out what to do about it (how to fix it)
code:
var_dump($each->promotion-type);
returns:
PHP Notice: Use of undefined constant type - assumed 'type' in newfile.php on line 19
I can't change that variable name as that how I get from my vendor, any ideas how I can access that promotion-type variable? (syntax wise)
Referring to a class constant without specifying the class scope.
Checking if a PHP Constant is Defined This can be achieved using the PHP defined() function. The defined() function takes the name of the constant to be checked as an argument and returns a value of true or false to indicate whether that constant exists.
Undefined Index in PHP is a Notice generated by the language. The simplest way to ignore such a notice is to ask PHP to stop generating such notices. You can either add a small line of code at the top of the PHP page or edit the field error_reporting in the php. ini file.
It's spitting that notice because the expression is being interpreted as variable $each->promotion
minus constant type
.
To access a property with the dash in its name, use curly braces and quotes:
var_dump($each->{'promotion-type'});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With