PHP variables error on customised menu [closed] - php

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Kindly help correct the code below:
PHP Strict Standards: Only variables should be passed by reference in /home/xxxxxx/public_html/app/mods/Controller/Menu.php on line 15
The code is as below:
public function __call($function, $parameters){
$categoria = strtolower(str_replace('Action',NULL,$function));
$platillo = strtolower(array_pop( array_flip($_GET)));//line 15
Thank you in advance

array_pop requires a reference to a variable. A reference means it has to be a variable - i.e. you can do:
$x = ["a", "b"];
array_pop($x);
but not
array_pop(["a","b"]);
So, to fix your issue, you would do:
$flipped_get = array_flip($_GET);
$platillo = strtolower(array_pop($flipped_get));//line 15

Related

Return type is array but string returned [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
IS there anything wrong in this declaration please help, am getting error:-
My code
public function function(): array
{
return $this->data['value'] ?? [];
}
Error am getting is:- Function should return an array but string returned.
Try this simple example, your function declaration is wrong :
<?php
function test() {
return $this->data['value'] ?? [];
}
$result = test();
?>

how to Insert comma between values in php [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
My value is coming like this with two enters. please see below :
125
124
132
I am getting this value by php variable and want to get values with commas in new php variable.
i want like this 125,124,132
anyone have an idea for that please?
$str = "125
124
132";
$str = str_replace("\r\n\r\n", ",", $str);
echo $str;
Try the above code. Please let know if this worked.
You can directly add commas between numbers using
number_format() function of PHP
<?php
echo number_format("125124132")."<br>";
?>
Answer:- 125,124,132
Try the above given code and let me know if this worked.....

Why passing variables through url in php not working? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I am trying to pass some variables through url in php. Im using the following script
$query1 = new ParseQuery("Drivers");
$query1->includeKey("driverUserId");
$query1->descending("createdAt");
$results1 = $query1->find();
$object1 = $results1[$i];
$uname=$object1->get('driverUserId');
echo ''.$uname->get('name').'';
echo '<td>'.$uname->get('name').'</td>';
echo '<td>'.$uname->get('username').'</td>';
But when I execute the page, script stopped working in this line.
echo ''.$uname->get('name').'';
When I removed '.$uname.' it worked fine.
Because if $uname has a ->get() method, it's obviously a class or an object and you can't directly use it like a string (if it hasn't any tostring modifiers). Try to write it like this (just guessing):
echo ''.$uname->get('name').'';
Use the below code:
$id=$uname->get('id');
$name=$uname->get('name');
echo ''.$name.'';

Disable errors when getting postal code using ipapi.co [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I'm retrieving the postal code by using -
<?php $pstcde = file_get_contents('https://ipapi.co/'.$_SERVER['REMOTE_ADDR'] . '/postal/'); ?>
It works great but if the postal code is not found, it says, "None". I can't find a way to disable the message.
You can empty the variable if the respond is None. With a simple check.
<?php
$pstcde = file_get_contents('https://ipapi.co/'.$_SERVER['REMOTE_ADDR'] . '/postal/');
if($pstcde === "None")
$pstcde = ""; //Empty string. Or you can use unset($pstcde); if you want to unset the variable.
?>

Fatal error: Function name must be a string whilst it shouldn't [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have stumbled over the following error in PHP:
"Fatal error: Function name must be a string in
F:\Applications\xampp\htdocs\BTB_Sandbox\uploads.php on line 15"
and I don't know what the real problem is. Here is line 15 that the error is pointing at:
$error = $_FILES(['file_upload']['error']);
I hope you could help me, because I am kind of stuck now.
You are using $_FILES as a function because of ().
That way, PHP tries to call a function named as var $_FILES value, but this value it not a string (that's the error reported), it is an array.
Obviously, in your code line you are failing to use $_FILES, the right way is:
$error = $_FILES['file_upload']['error'];

Categories