This question already has answers here:
Creating default object from empty value in PHP?
(18 answers)
Closed 8 years ago.
I am getting an warning message in my Wordpress :
"Creating default object from empty value in
/home/forthemde/public_html/wp-content/themes/mayadeep/admin/admin.php
on line 225"
Here the code on admin.php and:
function upfw_setup_theme_options(){
$up_options_db = get_option('up_themes_'.UPTHEMES_SHORT_NAME);
global $up_options;
//Check if options are stored properly
if( isset($up_options_db) && is_array($up_options_db) ):
//Check array to an object
foreach ($up_options_db as $k => $v) {
$up_options -> {$k} = $v;
}
else:
do_action('upfw_theme_activation');
endif;
}
add_action('upfw_theme_init','upfw_setup_theme_options',10);
add_action('upfw_admin_init','upfw_setup_theme_options',100);
Line 225 is here:
$up_options -> {$k} = $v;
I try to fix by myself, but no result. Please help me, really appreciate for any help.
Regards.
I had this problem too, recently, but this worked for me:
Just added $up_options = new stdClass(); after global $up_options;
Best regards,
http://shubhinfotech.com http://c-worx.com
Related
This question already has answers here:
unexpected T_DOUBLE_ARROW [closed]
(2 answers)
Closed 6 years ago.
Hi i'm learning some basic php, and i'm having some a parse error. It says that the error is located on line 8(if($book=>$find)). What is wrong with line 8?
function getPrice($find)
{
$books = array ("java"=>299,"c"=>348,"php"=>267);
foreach ($books as $book=>$price)
{
if($book=>$find)
{
return $price;
break;
}
}
}
thank you in advance :D
Use == or === to compare change here
if($book == $find)
Also no need to write break after return here
return $price;
break;
By the way you can also write your code like this
<?php
function getPrice($find)
{
$books = array ("java"=>299,"c"=>348,"php"=>267);
if(isset($books[$find])){
return $books[$find];
}
return false;
}
echo getPrice("java");
?>
Check here : https://eval.in/592069
Your syntax:
if($book=>$find)
is incorrect.
From what I see, it seems like you want to find a book which matches $find.
Try this instead:
if ($book==$find)
This question already has answers here:
Using braces with dynamic variable names in PHP
(9 answers)
Closed 6 years ago.
Using PHP variable variables with mysqli_fetch_assoc to auto-format variables like $column_name="some_value" (code below):
while ($account_row=mysqli_fetch_assoc($account_results))
{
foreach ($account_row as $key=>$value)
{
$$key=trim(stripslashes($value));
}
}
So if I have a column "username" and row value "someuser", this code creates:
$username="someuser";
However, in some cases I need variable names to be DIFFERENT from column names. For example, I need code to create:
$username_temp="someuser";
How could I do that? Using this code gives an error:
$$key."_temp"=trim(stripslashes($value));
No other ideas in my head.
change $$key."_temp" to ${$key."_temp"} have a look on below solution:
$value = 'test';
$key="someuser";
${$key."_temp"}=$value;
echo $someuser_temp; //output test
Please try this ${$key . "_temp"} = trim(stripslashes($value));
This question already has answers here:
Only variables should be passed by reference
(12 answers)
Closed 7 years ago.
I have the following code :
$_SESSION['aParties'] = time();
$aParties[] = $_SESSION['aParties'];
error_log(print_r($aParties,true), 3, "/var/tmp/error.log");
$first = reset(ksort($aParties));
The array aParties is like this :
Array
(
[0] => 1433841062
)
But I get the error :
'Only variables should be passed by reference in the method ksort'
Help me please! Thx in advance
You need to do it as
ksort($aParties);
$first = reset($aParties);
Note: There is no reference sign on a function call - only on function definitions. Function definitions alone are enough to correctly pass the argument by reference.
Check Docs
This question already has answers here:
Passing arrays as url parameter
(11 answers)
Closed 9 years ago.
$deposit=$_POST['amountdeposit'];
$arr= array();
for($i=0;$i<10;$i++)
{
if($arr[$i]=='\0')
{ $arr[$i]= array("$deposit");
}
break;
}
$page= "step2.php?arr=$arr";
header("Location:$page");
?>
what i want to do is each time there's a change in $deposit , this value is stored in $arr[$i] and then it is passed in a url so that i could use GET on that step2.php page.
What I see is just arr=array instead of values :/ please help me.
You want http_query_string. It will do exactly what you want.
A couple of other comments have recommended http_query_string, however I would use serialize along with urlencode.
Replace:
$page= "step2.php?arr=$arr";
with:
$page= "step2.php?arr=" . urlencode(serialize($arr));
Then when you get to step2.php, unserialize(urldecode($_GET['arr'])) will contain your array as you originally built it.
This question already has answers here:
PHP Object Variable variables name?
(5 answers)
Closed 9 years ago.
Why does this work
foreach ($items as $i) {
$dataTitle = $this->dataTitle;
$title = $i->$dataTitle;
}
when this doesn't?
foreach ($items as $i) {
$title = $i->$this->dataTitle;
}
Is there a better way to do this?
Try this:
$title = $i->{$this->dataTitle};
Your expression is being parsed as:
$title = ($i->$this)->dataTitle;
$this referes to current object parsed in not obvious order. You need to use {expr} notation, to dynamicly evaluate property name.
Try to use {} around $this->dataTitle:
$title = $i->{$this->dataTitle};
Look at bottom part of last example in variable variables section of manual.