in Code Igniter i have declared some constants in constatnts.php like this
define('TEST',$_REQUEST['test']);
but they are not working and showing the error like Notice: Undefined index: testin C:\xampp\htdocs\userinterface\application\config\constants.php on line 39
what should i do?
The error is saying that the superglobal $_REQUEST does not have an item with the index of 'test'.
In other words, isset($_REQUEST['TEST'] === FALSE
You need to test that it is set before trying to use it to define the constant.
if(isset($_REQUEST['TEST']))
{
define('TEST',$_REQUEST['test']);
}
In this case, because the constant may not get defined, you always need to make sure it exists before you use it.
if(defined("TEST"))
{
echo TEST;
}
Related
Controller Code:
$tokenAmount = json_decode($token->getBody())->result;
return view('account')->with(compact('tokenAmount'));
View Code:
<label>Wallet Balance {{tokenAmount}}</label>
When I run the code. I'm getting following error.
Use of undefined constant tokenAmount - assumed 'tokenAmount'
PS: I tried following method also.
$tokenAmount = json_decode($token->getBody())->result;
return view('account', compact('tokenAmount'));
If I do echo $tokenAmount, it is printing the value without any error.
Please update your view code and check like:
<label>Wallet Balance {{tokenAmount}}</label>
to
<label>Wallet Balance {{$tokenAmount}}</label>
Trying to use the member function of the puppet stdlib module:
effectively:
$myvariable = 'FOO'
then when using the member function:
member(['FOO','BAR'], $myvariable)
I keep getting the error message:
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Function 'member' must be the value of a statement at /etc/puppet/modules/mymodule/manifests/init.pp:###
Looking at the stdlib documentation for member, we see that member is an rvalue. This means in this context that you need to have its output assigned. This is what the error message of must be the value of a statement is hinting at. Note a helpful wikipedia article on l-values and r-values https://en.wikipedia.org/wiki/Value_(computer_science)#lrvalue.
Your code will work, for example, if you assign the output of member(['FOO','BAR'], $myvariable) to a variable or a resource attribute.
For example:
$myvariable = 'FOO'
$variable = member(['FOO','BAR'], $myvariable)
notify { $variable: }
will result in a notify 'true' during compilation.
Mail::send('emails.cont',['name'=>$n,'email'=>$email],function($message){
$message->to('abc#gmail.com','efe')->from('cde#gmail.com')->subject($s);
});
There for the subject, I am trying to pass a variable called $s which contains a value which defined there. But, it will underlying in red and saying undefined variable called $s. How to solve that?
can you please try the following code
Mail::send('emails.cont',['name'=>$n,'email'=>$email],function($message) use ( $s ) {
$message->to('abc#gmail.com','efe')->from('cde#gmail.com')->subject($s);
});
This is the error:
No 'new' for class 'Spec::Benchmark::bzip2401' in 'C:/Users/Tester/Documents/SpecINT2k6_WoT/benchspec/CPU2006/401.bzip2/Spec/object.pm'
point of error in locate.pl file:
my $class="Spec::Benchmark::${name}${num}";
if (!$class->can('new')) {
Log(0, "\nNo 'new' for class '$class' in '$pm'\n");
next;
}
here is the link to the whole locate.pl file http://ks.tier2.hep.manchester.ac.uk/Repositories/other-software/SPEC_CPU2006v1.1/bin/locate.pl
This is the object.pm file http://codepad.org/O196ykIq
I am getting this error while running Specint2006 suite, but this error is not related to the suite. Can anyone tell me what does !$class->can('new') do and why is it returning true here?
Thanks.
Can checks if the Class has the method. The return value is always the coderef. If the class dont know the method, the return value is undef.
The Class dont know the new method, so its false. But you call it with not
!$class->can('new')
Quote from HERE
Again, the same rule about having a valid invocand applies -- use an eval block or blessed if you need to be extra paranoid.
I spent more than 10 hours to find out the typo for debugging my PHP program. I expected PHP would produce an error when using an undefined variable. But when it is used as an object in a method, it doesn't. Is there a reason for it?
<?php
$oClass = new MyClass;
// $oCless->tihs('key', 'taht'); //<-- triggers the error: Notice: Undefined variable
$oClass->tihs('key', 'taht');
echo $oClass->arr['key'];
class MyClass {
public $arr = array('key' => 'foo');
function tihs($key, $value) {
$tihs->arr[$key] = $value; //<-- this does not cause an error message.
}
}
?>
Normally if the error reporting level is set to E_ALL | E_STRICT (or E_ALL as of PHP 5.4.0) it should spit out an E_STRICT error. For instance, this code:
error_reporting(E_ALL | E_STRICT);
$tihs->adrr = 453;
Produces:
Strict Standards: Creating default object from empty value in [...]
Interestingly enough, if you specifically create an array instead of an ordinary variable as a property of an object that doesn't exist, e.g.:
error_reporting(E_ALL | E_STRICT);
$tihs->adrr[25] = 453;
No strict standards error is shown! It looks like this could potentially be something PHP folks might want to fix, because I'm not aware this is documented nor I think there's a legitimate reason for this behaviour.
For the record, in both cases regardless of the error a new stdClass is being created on the fly instead, like sberry mentions in his answer.
It is because of PHP trickery...
Under the covers, PHP is actually creating an object called tihs, adding an array to the object called arr and setting key to value.
Here is a print_r($tihs); after the assignment:
stdClass Object
(
[arr] => Array
(
[key] => taht
)
)
You seemed to have misspelt $oClass as $oCless
Agreed, $oCless instead of $oClass would give you an undefined variable error.
Also, "this" is a keyword in most languages and may be in php as well. You should refrain from using it so that it doesn't come out in other languages as a habit. You'll get way more errors if you're using "this" as function and variable names. You wouldn't even get things to compile.