PHP - Need Help Figuring Out An Exception To A Soapcall
at this point, I've authenticated with the login service, and I believe I'm now passing the cookie correctly to the ADBAccess service, but when I do a soapcall to getCMSData, I'm getting an exception.
Here's the relevant code: $agDataService->__setCookie('cookie', $s_Cookie); $a_includeList[0]="*"; $a_getCMSTables_args['opName']='accounts'; $a_getCMSTables_args['startDate']='01/07/2011'; $a_getCMSTables_args['endDate']='01/08/2011'; $a_getCMSTables_args['lastID']=''; $a_getCMSTables_args['includeList']= a_includeList; $agTables = $agDataService->__soapCall('getCMSData', $a_getCMSTables_args, null, new SoapHeader('http://webservice.agemni.com', 'cookie', $s_Cookie)); and here's the exception: System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object. at ADBAccess.setErrorXML(XmlDocument& responseDoc, XmlElement& DocRoot, String ErrorMessage, Int32 ErrorNum, Int32 numRecords) at ADBAccess.getCMSData(String opName, String startDate, String endDate, String lastID, String[] includeList) --- End of inner exception stack trace --- any ideas? Similar TutorialsGett an error from some custom code I inherited in a WordPress installation. Here is the error... Code: [Select] Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct() [<a href='datetime.--construct'>datetime.--construct</a>]: Failed to parse time string (--) at position 0 (-): Unexpected character' in /home2/history8/public_html/bee/wp-content/themes/makinghistoryblue/beeteachers.php:27 Stack trace: #0 /home2/history8/public_html/bee/wp-content/themes/makinghistoryblue/beeteachers.php(27): DateTime->__construct('--') #1 /home2/history8/public_html/bee/wp-includes/plugin.php(395): bee_teachers('') #2 /home2/history8/public_html/bee/wp-admin/admin.php(151): do_action('bee_teachers', Array) #3 {main} thrown in /home2/history8/public_html/bee/wp-content/themes/makinghistoryblue/beeteachers.php on line 27 Here is the code... Code: [Select] <?php $teachers = $wpdb->get_results("SELECT * FROM bee_teachers,bee_postmeta WHERE bee_teachers.statebee=bee_postmeta.post_id and meta_key='regional_date' ORDER BY meta_value ASC"); $today = new DateTime(); foreach ($teachers as $teacher): $site = get_post($teacher->statebee)->post_title; $date = new DateTime($teacher->meta_value); // this is line 27, mentioned in the error if($date<$today) $style=' style="color:#999"'; else $style=''; ?> If I remm out these lines, the query works, just no styling difference based upon date... Code: [Select] $date = new DateTime($teacher->meta_value); // this is line 27, mentioned in the error if($date<$today) $style=' style="color:#999"'; else $style=''; Thoughts? This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=358486.0 So I have been reviewing my codebase that i stepped away from for a couple of years. Surprisingly (or not), so far I understand almost all of my code. But I have a function that **** out dirty words, and there is one section of the code that isn't making sense. (I added var_dumps, but I'm just not seeing what it is doing.) Below is slightly simplified code - since my real code uses the database plus a bunch of words I can't post here! I have added comments where I'm hung up... <?php // Initialize Variables. $patternsArray = array(); $replacementsArray = array(); $tempArray = array(); $matchesArray = array(); // Un-censored text. $text = "Cassie, slipped on some glass and cut her ass!<br> 'Goshdamnit! Who left this damn mess out?' she cried.<br> 'Well, SHOOT, you should be more careful!' Mary laughed.<br> 'Hello! Why don't you clean up after yourself!' Cassie screamed.<br> 'Go to HELL!' Mary yelled back.<br> Then suddenly, blood started shooting everywhere."; // Create Replacements. $replacementsArray[0] = '***'; // ass $replacementsArray[1] = '****'; // damn $replacementsArray[2] = '****'; // shoot $replacementsArray[3] = '****'; // hell // Create Patterns. $patternsArray[0] = "/\b(ass)(s?)\b/i"; // Word pattern $patternsArray[1] = "/damn/i"; // Substring pattern $patternsArray[2] = "/\b(shoot)(s?)\b/i"; // Word pattern $patternsArray[3] = "/\b(hell)(s?)\b/i"; // Word pattern // Sort Arrays. // ksort($patternsArray); // ksort($replacementsArray); // What does this do???? foreach ($patternsArray as $pattern){ preg_match_all($pattern, $text, $tempArray, PREG_PATTERN_ORDER); // (1) // preg_match_all($pattern, $text, $matchesArray, PREG_PATTERN_ORDER); // (2) $matchesArray = array_merge($matchesArray, $tempArray[0]); // (3) /* If I comment (1) and (3) and uncomment (2), * then var_dump($matchesArray) displays nothing. * Not realy sure what this block of code does... */ } // Clean text. $cleanText = preg_replace($patternsArray, $replacementsArray, $text, $limit=-1, $allCount); ksort($matchesArray); echo "<b>DIRTY TEXT:</b><br> $text"; var_dump($patternsArray); var_dump($replacementsArray); var_dump($tempArray); var_dump($matchesArray); echo "<b>CLEAN TEXT:</b><br> $cleanText"; ?>
In the test I run locally - again I couldn't really post that here - my function seems to work, but I don't see how the parts i commented above work/help get the end results I want. The goal of reading all of my code line-by-line is to UNDERSTAND it, so that when I go to code my final module, I know my head is in the game. Thanks. Edited February 6 by SaranacLake This PHP program has been haunting IT around the world, see if you can correct it? Its open source code!
Errors:
Notice: Uninitialized string offset: 0 in C:\wamp\www\language_files\language.inc.php on line 33
Notice: Undefined offset: 2 in C:\wamp\www\language_files\language.inc.php on line 50
Code:
<?php
$strLangShort = $_REQUEST['language']; if ($strLangShort == '') { $strLangShort = $_REQUEST['strLanguage']; } $strFilename = 'gui_'.$strLangShort.'.langprop'; $strLanguagePath = "../language_files/".$strFilename; $pFile = @fopen($strLanguagePath, "r"); if ($pFile == null) { $strLanguagePath = "language_files/".$strFilename; $pFile = @fopen($strLanguagePath, 'r'); if ($pFile == null) { $strLanguagePath = "../../language_files/".$strFilename; $pFile = @fopen($strLanguagePath, 'r'); } } $arrTranslation; if (null != $pFile) { while (!feof ($pFile)) { $strLine = trim(fgets($pFile, 4096)); if ( ($strLine[0] != "#") && (strlen($strLine) > 0) && (substr($strLine,0,5)!="_jotl")) { $nPos = strpos($strLine, "="); $strId = substr($strLine, 0, $nPos); $strRest = trim(substr($strLine, $nPos+1)); $arrInfos = explode("@@@", $strRest); $strValue = $arrInfos[0]; $arrTranslation[$strId] = $strValue; } else { $nPos = strpos($strLine, "="); $strConfig = substr($strLine, 0, $nPos); $splitConfig = explode (".", $strConfig); if ($splitConfig[2] == 'encoding') { $DEFAULT_CHARSET = trim(substr($strLine, $nPos+1)); } } } fclose($pFile); } $CIRCULATION_MNGT_ADDCIRCULATION; foreach($arrTranslation as $key => $value) { $$key = $value; } function escapeSingle($string) { return str_replace("'", "\\'", $string); } function escapeDouble($string) { return str_replace("\"", "\\\"", $string); } ?> So basically I have a function that grabs a daily bible scripture via an rss feed. For whatever reason, it is offline today and I was greeted with a huge paragraph of errors and the bottom part of my page not rendering. Here is the function: Code: [Select] <?php function scripture(){ function fetchXML($url) { $ch = curl_init(); $useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1"; curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_USERAGENT, $useragent); //get data $data = curl_exec($ch); curl_close($ch); return $data; } define("USE_CURL", true); $url = "http://www.mybiblescripture.com/rss/bible.php?fmt=daily&trans=KJV"; //get xml doc with info $data = fetchXML($url); //create a SimpleXML object to parse the xml $char_xml = new SimpleXmlElement($data); $scripture_a=$char_xml->channel->item->description; $scripture_b=$char_xml->channel->item->title; echo $scripture_a . '<br><b>'. $scripture_b. '</b>'; } ?> And here is the nasty error I receive due to the url being offline: Code: [Select] Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /path/lbcfunc.php:21 Stack trace: #0 /path/lbcfunc.php(21): SimpleXMLElement->__construct('') #1 /path/index.php(31): scripture() #2 {main} thrown in /path/lbcfunc.php on line 21 I have 0 experience in catching exceptions and unsure where to start. I would like to try and just echo: "No Bible Scripture Found" as a friendly message instead I guess. thanks. Hey Guys. I am across this in a book and I am having a hard time understanding how I can try/catch this expception
The code below will throw an exception if I add an unit object into Archer or LaserCannon object.
Here is a quick example
class UnitException extends Exception{} abstract class Unit{ function AddUnit(Unit $unit){ throw new UnitException(get_class($this)."is a leaf"); } function removeUnit(Unit $unit){ throw new UnitException(get_class($this)."is a leaf"); } abstract function bombardStrength(); } class Archer extends Unit { function bombardStrength(){ return 4; } } class LaserCannonUnit extends Unit { function bombardStrength(){ return 44; } } $laser_cannon = new LaserCannonUnit(); $laser_cannon->AddUnit(New Archer()); // This is not allowedWhen I run the client code I get the following error message Fatal error: Uncaught exception 'UnitException' with message 'LaserCannonUnitis a leaf' Can any please help me understand this?? Thanks! Hey, I'm wondering what the issue is, I'm new to using PDO and objects so I'm sure this is a common error but setting me on the right track would be greatly appreciated. Code: [Select] Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 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 'AND password = d41d8cd98f00b204e9800998ecf8427e' at line 1' in /Users/JPFoster/Sites/Jaipai.Blog/engine.php:47 Stack trace: #0 /Users/JPFoster/Sites/Jaipai.Blog/engine.php(47): PDO->query('SELECT * FROM u...') #1 /Users/JPFoster/Sites/Jaipai.Blog/index.php(7): SiteEngine->login('', '') #2 {main} thrown in /Users/JPFoster/Sites/Jaipai.Blog/engine.php on line 47 Code: [Select] public function login($user, $pw){ $user = addslashes($this->user); $pw = md5($pw); $query = "SELECT * FROM users WHERE username = ".$user." AND password = ".$pw; //set up query $results = $this->pdo->query($query); $num_rows = $results->num_rows; if ($num_rows == 1){ $row = $results->fetch_assoc(); echo "Worked!"; //$this->set_session($row['id'], $row['username'], $row['email']); } else { echo "Your Username and Password did not match"; } //if user + passs match { redirect (member page) and set up sessions // Else ... Retry... } } I don't see an issue with my query, and the object is instantiated by having the submit button isset() and i use login($_post[user], $_post[pw]) How to get cURL timedout Exception or cURL timedout Message ? Hi ! I was seeing the Exception class defined in basic.php and I found that all the methods are final and without body: Code: [Select] final public function getMessage () {}But if I call MyCustomException->getMessage() I get the message. How does it works?? hello to all,
My issue is that i have a script encoded with zend and the script some pages work some are just BLANK
Zend it is installed :
This program makes use of the Zend Scripting Language Engine: Zend Engine v2.4.0, Copyright © 1998-2014 Zend Technologies with the ionCube PHP Loader v4.7.1, Copyright © 2002-2014, by ionCube Ltd., and with Zend Guard Loader v3.3, Copyright © 1998-2013, by Zend Technologies Configuration File (php.ini) Path /usr/local/lib Loaded Configuration File /usr/local/lib/php.ini and Its throwing exception he Can someone please help cuz i am tryin like a week to fix it but no results Edited by SSopranos, 07 January 2015 - 02:21 PM. Hi guys, I'm reviewing a piece of small web application and the current application does not have any error / exception handling capability. If there is any error, it would simply show an error message followed by die;. I'm planning to implement a simple exception handling class to handle the errors. What I'm thinking is a simple redirect when an error is being caught together with an error code that correspond to an error message in a simple flat text file. The error page will then show an error message that corresponds to the code. Here's what I have so far. Would appreciate if the PHP experts here would give simple pointers to enhance it. <?php class MyException extends Exception {} try { throw new MyException("error.php"); } catch (MyException $e) { $file = $e->getMessage(); header("Location: $file?e=1"); } ?> This is what I have on my error.php page <?php $errorcode = $_GET['e']; function getErrorMessage($errorcode) { $errors = file("english.txt"); foreach ($errors as $error) { list ($key,$value) = explode(",",$error,2); $errorArray[$key] = $value; } return $errorArray[$errorcode]; } echo "Test <br />"; echo getMessageMap($errorcode); ?> As you can see here, exception class would redirect user to error.php if an error is caught together with a GET variable on the URL. On error.php page, it would GET the error code and then run it through a function to get the error message of the corresponding error code and then echos it out. Was wondering if this is a good practice? My ultimate goal here is to avoid displaying the error message itself on private includes file. Thank you in advance for your suggestions. This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=310162.0 In drive.php
public function insert($postBody, $optParams = array()) I know this is stupid newbie stuff, but I can't think about this the right way. And this question might very well make NO sense. If so, I apologize in advance. I'm trying to consolidate code. I basically have lots of quizzes, all with their own answers, which I compare using AJAX. I had individual pages for each quizzes answers to do that comparison and everything was working fine. It would do the following... Code: [Select] <?php $userinput = strval($_GET['userinput']); $userinput= trim($userinput); $userinput = strtolower($userinput); switch ($userinput) { case 'heat': case 'miami heat': echo 'Miami Heat'; exit; case 'magic': case 'orlando magic': echo 'Orlando Magic'; exit; case 'jazz': case 'utah jazz': echo 'Utah Jazz'; exit; default: echo 'incorrectguess'; } ?> But now I am storing the answers in a MySQL database (for example, one answer set is in the database as "Miami Heat/heat/miami"...each allowed answer is separated by a "/", with the first answer being the "main" correct answer). So now, I want to just have ONE "comparison" page and populate the "cases" into that page dynamically, from the database. This is what I came up with so far, but it's not working... Code: [Select] <?php $userinput = strval($_GET['userinput']); $userinput= trim($userinput); $userinput = strtolower($userinput); if ($_GET['quizid'] == "") { redirect_to('index.php'); } else { $quizid=$_GET['quizid']; } $sql = "SELECT * FROM answers WHERE quizid = $quizid"; $result = mysql_query($sql, $connection); if (!$result) { die("Database query failed: " . mysql_error()); } else { switch ($userinput) { while ($results = mysql_fetch_array($result)) { $answers = explode("/", $results['answer']); $n = count($answers); for ($i=1; $i < $n; $i++) { case '$answers[$i]': } echo '$answers[0]'; exit; default: echo 'incorrectguess'; } } ?> What I'm having trouble grasping is where I need to use "echo" or NOT use "echo". For example, where I have "switch ($userinput) {" in the NEW code, does that need to actually be "echo 'switch ($userinput) {';"? I'm trying different combos and failing, so just curious if someone can help me understand what, if anything, needs to be echoed when doing it the 2nd way (dynamic info) rather than the 1st way (static info) I'm sure it's not much, but I'm not understanding something with custom error handlers: I've created a custom error handler, which I initially set when my page loads : set_error_handler(array ( new ErrorHandler(), 'handleError' ));
It seems to catch all internal PHP errors, such as if I: var_dump($non_existing_var); right after the set_error_handler.... Now, I have an object that throws an exception after: set_error_handler(array ( new ErrorHandler(), 'handleError' )); $locale = new \CorbeauPerdu\i18n\Locale(...); // this should throw an exception ... I thought that with an error handler set, I could 'skip' the try/catch for it, but doing so, PHP spits out in its internal log: PHP Fatal error: Uncaught CorbeauPerdu\i18n\LocaleException: ....
My error handler doesn't catch it at all before, thus my page breaks!! If I want it to go through the error handler, I have to init my Locale with a try/catch and use trigger_error() like so: set_error_handler(array ( new ErrorHandler(), 'handleError' )); try { $locale = new \CorbeauPerdu\i18n\Locale(...); // this should throw an exception } catch(Exception $e) { trigger_error($e->getMessage(), E_USER_ERROR); } ... Is this normal ? I thought one of the goals of the error_handler was to catch anything that wasn't dealt with? Thanks for your answers! Hi I am implementing a read-only access to some specific attributes of a class via the magic __get method. I intend to raise an exception when trying to write to it using __set, but I'm not sure which exception is suitable to use. Is there any predefined exception to indicate such an error or should I just go ahead and define my own? Hello all,
Appreciate if you folks could pls. help me understand (and more importantly resolve) this very weird error:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 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 'ASC, purchase_later_flag ASC, shopper1_buy_flag AS' at line 3' in /var/www/index.php:67 Stack trace: #0 /var/www/index.php(67): PDO->query('SELECT shoplist...') #1 {main} thrown in /var/www/index.php on line 67
Everything seems to work fine when/if I use the following SQL query (which can also be seen commented out in my code towards the end of this post) :
$sql = "SELECT shoplist.*, store_master.store_name, item_master.item_name FROM shoplist, store_master, item_master WHERE shoplist.store_id = store_master.store_id AND shoplist.item_id = item_master.item_id";However, the moment I change my query to the following, which essentially just includes/adds the ORDER BY clause, I receive the error quoted above: $sql = "SELECT shoplist.*, store_master.store_name, item_master.item_name FROM shoplist, store_master, item_master ORDER BY purchased_flag ASC, purchase_later_flag ASC, shopper1_buy_flag ASC, shopper2_buy_flag ASC, store_name ASC) WHERE shoplist.store_id = store_master.store_id AND shoplist.item_id = item_master.item_id";In googling for this error I came across posts that suggested using "ORDER BY FIND_IN_SET()" and "ORDER BY FIELD()"...both of which I tried with no success. Here's the portion of my code which seems to have a problem, and line # 67 is the 3rd from bottom (third last) statement in the code below: <?php /* $sql = "SELECT shoplist.*, store_master.store_name, item_master.item_name FROM shoplist, store_master, item_master WHERE shoplist.store_id = store_master.store_id AND shoplist.item_id = item_master.item_id"; */ $sql = "SELECT shoplist.*, store_master.store_name, item_master.item_name FROM shoplist, store_master, item_master ORDER BY FIND_IN_SET(purchased_flag ASC, purchase_later_flag ASC, shopper1_buy_flag ASC, shopper2_buy_flag ASC, store_name ASC) WHERE shoplist.store_id = store_master.store_id AND shoplist.item_id = item_master.item_id"; $result = $pdo->query($sql); // foreach ($pdo->query($sql) as $row) { foreach ($result as $row) { echo '<tr>'; print '<td><span class="filler-checkbox"><input type="checkbox" name="IDnumber[]" value="' . $row["idnumber"] . '" /></span></td>';Thanks |