PHP - No Warnings Displayed If I Reference Arguments At Call Time For A Function
Hello,
I was trying out some code to check out how some of the php settings work and when i tried allow_call_time_pass_reference to see if it works, it doesn't spew out any warning or error like the comments in the .ini file mention (or in the manual sites). Maybe i'm not using some other setting in order to see this? Here is my EXACT code. <?php ini_set('display_errors',1); error_reporting(-1); $variable = 'String'; function display($variable) { return $variable; } echo display(&$variable); ?> Outputs : String. No errors, no warnings. I'm running PHP Version 5.3.2-1ubuntu4.5 Similar TutorialsHello all I just got some errors in my script This is it: Deprecated: Call-time pass-by-reference has been deprecated in cls_xml.php on line 61 Deprecated: Call-time pass-by-reference has been deprecated in cls_xml.php on line 164 Deprecated: Call-time pass-by-reference has been deprecated in cls_xml.php on line 316 This is my script lines 61 : xml_set_object($this->parser, &$this); 164: array_push($toreturn, &$this->ownerDocument->nodes[$i]); 316: $text=trim(&$this->ownerDocument->nodes[$j]->text); What can be the problem for this error.What can cause it. thank you in advance for your help So does it mean that you cannot call variables by reference in newer version of php? Why is it deprecated? Is it abad thing or what? Any help is appreciated. I have a odd one here, two classes and one which calls another class. I want to pass all of the parameters from the array as seperate variables into the next function. Hope my example explains a little better class master{ public function __call($name, $args) { second->$name($args); }}class second{ public function example($param1, $param2) { }}master->example($param1, $param2);() ( i know its not accurate php, but should get the idea of what im trying to do) I need to do something with the following line second->$name($args); Where param1 and param2 will be seperated out Is there a php function which you can tell it the class, method name and pass it an array of parameters? Thanks Hello I've have read that global variables should not be used. so if i have 2 .php files: index.php - main content php file sitefunctions.php - php functions site file on my index.php page i have the following (an example of my problem): <?php displayError($errorID); ?> and in the sitefunctions.php file i have the following (an example of my problem): <?php function displayError($errorID) { if($errorID == 1) { echo "Password Failure"; } else { echo "Other Failure"; } } ?> now that works but since when first accesing that page the $errorID is not set then i get an error. How can i achieve this without first setting a blank $errorID global variable? Thanks I need someone to explain how to loop through an array ($products) and grab the three values (name, price, & shipping) and have them sent to "all_products" function - see line 13 then 61 thru 64. I currently have the script partially working by using array_shift which I know is removing the 1st element (name or $product value). Note: this is the problem (I need $product included in the call to the "all_products" function along with $price & $shipping so that the final output looks as follow: --------------------------------- Checkout Below is a summary of the products you wish to purchase, along with totals: * Candle Holder: $12.95 * Coffee Table: $99.5 * Lamp: $42.99 Total (including tax and shipping): $182.12 ------------------------------------------------------ HERE'S THE SCRIPT FOR REVIEW & COMMENT: =============================== <B>Checkout</B><br> Below is a summary of the products you wish to purchase, along with totals: <?php /* Fix this code by creating a function to determine sub-totals for each product. Then add the sub-totals together to arrive at the grand total.The product name, & price should display for each item. ?><ul><? /* "all_products" function was created to query then calculate the sub-totals for each prodcut, then add each sub-total togehter to form grand total - outside the function */ function all_products($prod_array) { extract($prod_array); #tax rate is constant $tax = 0.08; $total_price = 0; $total_tax = 0; $total_shipping = 0; // Calculations per product with returned sum sent outside to $grand_total variable $total_price += $price; $total_tax += $tax * $price; $total_shipping += $shipping * $price; $sub_total = ($total_price + $total_tax + $total_shipping); # This calculates the sub-total (or Grand total) for each product echo "<li>".$product.": $".$price."<br />"; # THE PRODUCT NAME & PRICE SHOULD DISPLAY HERE (NAME IS NOT SHOWING WHICH IS PROBLEM) # I had echo statement to confirm calculation on product was correct # echo "Grand Total is $".$sub_total."<br />"; return $sub_total; # This breaks out of the function when Candle Holder IF statement is true; returning value } /* Keep the functions, and add a two-dimensional array that acts as a product database -- it should contain the name, price, and shipping price for every product -- and use list() and each() to traverse the database. */ // Products array with List / Each configuration to pass arguements into function $products = array('Candle Holder' => array('price' => '12.95','shipping' => '0.00'), 'Coffee Table'=>array('price' => '99.50','shipping' => '0.10'), 'lamp' =>array('price' => '99.50','shipping' => '0.10')); while (list($k, $v) = each($products)) { $product = $k; # This is individual product name extracted from array #echo "Here's the price & shipping cost for ".$product.":<br/>"; while (list($key, $value) = each($v)) { if (array_key_exists('price',$v)) { $price = $value; #echo "The product ".$key." is: $".$value."<br />"; } if (array_key_exists('shipping',$v)) { $shipping = $value; #echo "The ".$key." cost is: ".$value."<br />"; } } } # THE BELOW THREEE LINES TRAVERSE THE ARRAY BUT STRIPPING THE 1ST ELEMENT WHICH IS NOT WHAT I WANT; I NEED THE INCLUDED TO DISPLRAY BEFORE PRICES $sub_total1 = all_products(array_shift($products)); $sub_total2 = all_products(array_shift($products)); $sub_total3 = all_products(array_shift($products)); echo "RESULTS OUTSIDE FUNCTION: ".$sub_total1."<br />"; echo "RESULTS OUTSIDE FUNCTION: ".$sub_total2."<br />"; echo "RESULTS OUTSIDE FUNCTION: ".$sub_total3."<br />"; // Add total sum for each product to define grand total for all products including shipping & taxes $grand_total = $sub_total1 + $sub_total2 + $sub_total3; ?> </ul> <hr> <br> <?php # Below is the "GRAND TOTAL" for all three project - displayed outside the function which should be $182.12 USD ?> <B>Total (including tax and shipping): $<? echo number_format($grand_total, 2); ?></B> This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=319682.0 Hi, when I browse my php website I recieve sometimes error 504. when it happens I try to refresh and get this error: Gateway Time-out The gateway did not receive a timely response from the upstream server or application. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. This website is in a shared hosting. Where can I find logs that will help me correct the issue? Thank you. I can call the following function successfully as a single php program // Acknowledge and clear the orders function ack($client, $merchant, $id) { $docs = array('string' => $id); $params = array('merchant' => $merchant, 'documentIdentifierArray' => $docs); $result = $client->call('postDocumentDownloadAck', $params); return $result; } with $result = ack($t, $merchant,'2779540483'); successful output [documentDownloadAckProcessingStatus] => _SUCCESSFUL_ [documentID] => 2779540483 I'm trying to figure out how to call this function as an object from another program. Trying the following gives error ***Call to a member function call() on a non-object*** function postDocumentDownloadAck($t, $merchant, $id) { $this->error = null; $docs = array('string' => $this->id); $params = array('merchant' => $this->merchant, 'documentIdentifierArray' => $docs); ** I've tried the following which does nothing $result = $this->soap->call('postDocumentDownloadAck', $params); ** I've tried the following - which gives error "Call to a member function call() on a non-object" $result = $this->t->soap->call('postDocumentDownloadAck', $params); if($this->soap->fault) { $this->error = $result; return false; } return $result; } *** calling program snippet for above function $merchant= array( "merchant"=> $merchantid, "merchantName" => $merchantname, "email"=> $login, "password"=> $password); $t = new AmazonMerchantAPI($merchantid, $merchantname, $login, $password); $documentlist= $t->GetAllPendingDocumentInfo('_GET_ORDERS_DATA_'); $docid = $documentlist['MerchantDocumentInfo'][$i]['documentID']; $docs = array('string' => $docid); $ackorders = $t->postDocumentDownloadAck($t, $merchant,$docs); Any ideas of what I'm doing wrong are greatly appreciated. This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=315384.0 The Business Logic is: If product is already purchased, upgrade the product I have a customer input form to get information, along with some fields which should be auto populated based on what the customer chooses. Screen Shot:
https://i.stack.imgur.com/Fkyim.png When we come to the shipping cost I am getting it from Magento, using a PHP function. form :
https://paste.ofcode.org/335FVUhpBGbazQtrcPLVQUs sp_cost.php
https://paste.ofcode.org/hvG2sP9TW9CEPgMMuKXNuw $results = getShippingEstimate('14419','1',"IN","642001"); How can i get country and zipcode from the user entry and return the shipping cost?
Edited April 26, 2019 by aveeva OK, so I have the following file that has database functions: <?php function dbDelete($param){ $conDelete = mysql_connect($url,'username','password',true); mysql_select_db('my_db',$conDelete); mysql_query($param,$conDelete); mysql_close(); if(isset($conDelete)){ mysql_close($conDelete); } } ?> I include the above file in a session handling file. But for some reason the new file can't call the above function as follows: <?php include_once 'the above stated file'; function timeOut(){ dbDelete("DELETE FROM acctussessi WHERE acctussessi_usid = '$sessius[0]'"); $_SESSION = array(); setcookie(session_name(),'',time()-4200); session_destroy(); } //CHECK FOR TIMEOUT REQUEST switch($_GET['xyz']){ case 'timeout': timeOut(); header("Location: /?xyz=timedout"); break; case 'logout': timeOut(); header("Location: /?xyz=loggedout"); break; case 'refresh': dbUpdate("UPDATE acctussessi SET acctussessi_time = ".time()." WHERE acctussessi_unid ='".$token."'"); break; } ?> dbDelete isn't being called inside of the TimeOut() function. The only way it works is by doing the following: <?php function timeOut(){ $_SESSION = array(); setcookie(session_name(),'',time()-4200); session_destroy(); } //CHECK FOR TIMEOUT REQUEST switch($_GET['xyz']){ case 'timeout': dbDelete("DELETE FROM acctussessi WHERE acctussessi_usid = '$sessius[0]'"); timeOut(); header("Location: /?xyz=timedout"); break; case 'logout': dbDelete("DELETE FROM acctussessi WHERE acctussessi_usid = '$sessius[0]'"); timeOut(); header("Location: /?xyz=loggedout"); break; case 'refresh': dbUpdate("UPDATE acctussessi SET acctussessi_time = ".time()." WHERE acctussessi_unid ='".$token."'"); break; } ?> But this is annoying and repetitive. What is going on? Thanks in advance. Im trying to understand the code below. (taken from an O'REILLY book) Im trying to get my head around this, so can anyone tell me if im thinking about this in the right way; The function (fix_names) borrows the values from $a1,$a2 and $a3 and puts them into $n1,$n2, and $n3. It then processes the strings contained within these newly created variables and then returns the processed values back into $a1,$a2,and $a3? The variables $n1,$n2, and $n3 cannot be echoed as they were created within the function.? Please correct me if im wrong. Code: [Select] <html> <head> </head> <body> <?php $a1 = "EDWARD"; $a2 = "thomas"; $a3 = "wriGHT"; fix_names($a1,$a2,$a3); echo $a1." ".$a2." ".$a3; function fix_names(&$n1,&$n2,&$n3) { $n1 = ucfirst(strtolower($n1)); $n2 = ucfirst(strtolower($n2)); $n3 = ucfirst(strtolower($n3)); } ?> </body> </html> Ok, starting around line 137 with the functions..... Commented well. Just not sure If im doing it right. Any help greatly appreciated. Basic stuff and still learning. Just trying to figure out if Im passing by reference correctly or if not how to do it. Thanks. php File is attached but heres a snippet. Thanks in advance. Peace, Adam // The grand total and the item total need to be passed BY REFERENCE. function show_table_contents($cart_items, $table, &$grand_total, &$item_total) I know that the following lines of code can be used to prevent errors from being displayed: Code: [Select] <?php error_reporting(0); ini_set('display_errors', 0); ?> Is there a reason to use one over the other? Is it better to use both? PHP date and time function is not showing correct time on my local system I have the following php code date_default_timezone_set("Africa/Lagos"); $date = date('d-m-y h:i:s'); echo "Server Time ".$date ."<br>"; echo "The time is " . date("h:i:sa")."<br>"; $current_datetime = date("Y-m-d") . ' ' . date("H:i:s", STRTOTIME(date('h:i:sa'))); echo "Current time1: ".$current_datetime . "<br>";
Output
Server Time 21-05-21 09:55:39
Expected Output
Server Time 21-05-21 10:55:39
Any help would be appreciated. Edited May 21 by Ponel This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=319071.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=308349.0 i have a problem i cant solved for cople of hours! this is the function: function show_posts($user_id,$limit=0){ $posts = array(); $user_string = implode(',', $user_id); $extra = " and id in ($user_string) "; if ($limit > 0){ $extra = "limit $limit"; }else{ $extra = ''; } $sql = "SELECT userid, caption, stamp, filename FROM photographs WHERE userid in ($user_string) order by stamp desc $extra"; //echo $sql; $result = mysql_query($sql) or die(mysql_error()) ; while($data = mysql_fetch_object($result)){ $posts[] = array( 'stamp' => $data->stamp, 'userid' => $data->userid, 'caption' => $data->caption, 'filename' => $data->filename, ); } return $posts; } and thats the full error: Warning: implode() [function.implode]: Invalid arguments passed in C:\wamp\www\includes\functions.php on line 12 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') order by stamp desc' at line 2 and the intresting thing that if i echo the sql i get a working one i checked it in phpmyadmin + it shows what it need to show in the index.php if i comment the "or die(mysql_error()) " here the sql when its do echo SELECT userid, caption, stamp, filename FROM photographs WHERE userid in (4,7,2) order by stamp desc limit 5 so y the hell this problem is keep coming? i really cant understand what wrong! tnx for the help! My error is 'Warning: implode() [function.implode]: Invalid arguments passed in /home/definiti/public_html/contact.php on line 73' Im not sure how to fix this error, as I looked online and it says that my implode() has the right layout too it.. Line 73 in my code (I took the HTML code out) is this line; Code: [Select] $message = implode("<br>\n", $messages); My whole code is; Code: [Select] <?php # PHP Copyright 2007, Thomas Boutell and Boutell.Com, Inc. # Edited by Definition Designs. $recipient = 'defenitiondesigns@googlemail.com'; $serverName = 'www.definition-designs.co.uk'; if ($_POST['send']) { sendMail(); } elseif (($_POST['cancel']) || ($_POST['continue'])) { redirect(); } else { displayForm(false); } function displayForm($messages) { global $login; $escapedEmail = htmlspecialchars($_POST['email']); $escapedRealName = htmlspecialchars($_POST['realname']); $escapedSubject = htmlspecialchars($_POST['subject']); $escapedBody = htmlspecialchars($_POST['body']); $returnUrl = $_POST['returnurl']; if (!strlen($returnUrl)) { $returnUrl = $_SERVER['HTTP_REFERER']; if (!strlen($returnUrl)) { $returnUrl = '/'; } } $escapedReturnUrl = htmlspecialchars($returnUrl); ?> <?php if (count($messages) > 0) { $message = implode("<br>\n", $messages); echo("<h4>$message</h4>\n"); } ?> <form method="POST" action="<?php echo $_SERVER['DOCUMENT_URL']?>"> <p> <b>Your</b> Email Address <input name="email" size="35" maxlength="35" value="<?php echo $escapedEmail?>"/> </p> <p> Your <b>Real</b> Name <input name="realname" size="35" maxlength="35" value="<?php echo $escapedRealName?>"/> </p> <p> Subject Of Your Message <input name="subject" size="35" maxlength="35" value="<?php echo $escapedSubject?>"/> </p> <p> <i>Please enter the text of your message in the field that follows.</i> </p> <textarea name="body" rows="10" cols="60"><?php echo $escapedBody?></textarea> <p> <input type="submit" name="send" value="Send Your Message"/> <input type="submit" name="cancel" value="Cancel - Never Mind"/> </p> <input type="hidden" name="returnurl" value="<?php echo $escapedReturnUrl?>"/> </form> <?php } function redirect() { global $serverName; $returnUrl = $_POST['returnurl']; $prefix = "http://$serverName/"; if (!beginsWith($returnUrl, $prefix)) { $returnUrl = "http://$serverName/"; } header("Location: $returnUrl"); } function beginsWith($s, $prefix) { return (substr($s, 0, strlen($prefix)) === $prefix); } function sendMail() { global $recipient; $messages = array(); $email = $_POST['email']; if (!preg_match("/^[\w\+\-\.\~]+\@[\-\w\.\!]+$/", $email)) { $messages[] = "That is not a valid email address. In format: You@something.com"; } $realName = $_POST['realname']; if (!preg_match("/^[\w\ \+\-\'\"]+$/", $realName)) { $messages[] = "The real name field must contain only alphanumeric characters, spaces and + or - signs."; } $subject = $_POST['subject']; if (preg_match('/^\s*$/', $subject)) { $messages[] = "Please specify a subject for your message. "; } $body = $_POST['body']; if (preg_match('/^\s*$/', $body)) { $messages[] = "Your message was blank. Fill out a message or Click Cancel to cancel message."; } if (count($messages)) { displayForm($messages); return; } mail($recipient, $subject, $body) or die("unable to send the mail!"); $escapedReturnUrl = htmlspecialchars($_POST['returnurl']); ?> <form method="POST" action="<?php echo $_SERVER['DOCUMENT_URL']?>"> <input type="submit" name="continue" value="Click Here To Continue"/> <input type="hidden" name="returnurl" value="<?php echo $escapedReturnUrl?>"/> </form> <?php } ?> I am using a PHP class (it is attached) for Google Analytics that I got from this link below: http://www.acleon.co.uk/?p=173 Unfortunately, it appears the Class has a PHP error: Warning: implode() [function.implode]: Invalid arguments passed in Galvanize.php on line 114 and line 181. This is line 114: setcookie('__utmc', implode('.', $this->UTMC), 0, $this->CookiePath, $this->getDomain()); Here is line 181: $urchinUrl .= '&utmcc=__utma%3D'.implode('.', $this->UTMA).'%3B%2B__utmz%3D'.implode('.', $this->UTMZ).'%3B'; I did not see UTMC and UTMZ declared anywhere in the Class. The class file is attached. Thanks for your help in advance. |