ifubad
-
Posts
158 -
Joined
-
Last visited
Never
Posts posted by ifubad
-
-
However, this makes things more difficult when using any autoloading mechanism (as you may be), in that case its best to store your exceptions within there own files.
cool, tried it and I understood your last reply. Thanks
What do you mean by autoloading mechanism and how does it make it more difficult?
-
You would simply define your exception classes within the one file. eg;
Thank you, that part I do know. What I was wondering is that if it was possible to store different exception classes in a single "include" file. That way, I figured it MAY make it easier to maintain all of the custom exceptions.
-
When using multiple catch for custom exceptions, as of now, I have the custom exception classes as separate include files. Like so
Catch block
catch(FileException $e){ $e->showError(); } catch(MailException $e){ $e->logError(); }
custom Exception classes
Filename: FileException.inc.php
class FileException extends Exception{ public function showError(){ die($this->getMessage()); } }
Filename: MailException.inc.php
class MailException extends Exception{ public function logError(){ error_log($this->getMessage(),1,'sysadmin@domain.com'); } }
Is it possible to keep the different custom exceptions in a single/central file? If so, can you provided a simple example on how to implement. Or, is it that when using multiple custom exceptions, they HAVE to be kept in separate files?
TIA
-
If I have FF3.5 installed, is FF2 different enough to be worth keeping on the system for layout testing purpose?
TIA
-
microsoft took it over in the end
Cooool, I always wanted to pay several hundred $$$ for my copy of PHP anyway.
-
I read some articles from 2004 saying PHP may possibly be taken over by Sun in the future? Is this just a farce?
Hope the speculation stays that way
-
Got the following first custom Exception example from w3schools. The second example is a slightly modified version, that is not using a custom Exception, and outputs exactly the same message, with slightly less code overall. As stated by somewhere explaining why use a custom exception, because "The default exception class doesn't exactly fulfill the graceful part of handling unpredictable results. It just prints out an error message not much different from regular errors."
So, what is the big advantage of using a custom exception, if the more graceful message can be printed out within the echo statement of the catch block, when using the default Exception class. To produce cleaner code?
Using custom Exception
<?php class customException extends Exception { public function errorMessage() { //error message $errorMsg = 'Error on line '.$this->getLine().' in '.$this->getFile() .': <b>'.$this->getMessage().'</b> is not a valid E-Mail address'; return $errorMsg; } } $email = "someone@example...com"; try { //check if if(filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE) { //throw exception if email is not valid throw new customException($email); } } catch (customException $e) { //display custom message echo $e->errorMessage(); } ?>
Using default Exception
<?php $email = "someone@example...com"; try { //check if if(filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE) { //throw exception if email is not valid throw new Exception($email); } } catch (Exception $e) { //display custom message echo 'Error on line '.$e->getLine().' in '.$e->getFile() .': <b>'.$e->getMessage().'</b> is not a valid E-Mail address'; } ?>
-
I finally had some free time after working an 80 hr week, taking care of my kid & painting the house, so I put aside 10 hrs and completely finished the coding & calculations for ya
<?php echo 'Procrastination' . ' = ' . 'F'; ?>
-
The concept behind this is a centralized point to store variables that contain some globally pertinent information, but not having to change the variable across multiple files.
Ahhh, either an include or ini file, kinda like below(of course the Constants class would actually be in a different file). I guess one can either use a class as below to store the constants, or a simple include with constants created by define(). Which method of storing constants would be the preferred/correct way out of these two, using const in a class or the procedural define()?
For a medium to large site, would storing lots of constants and other pertinent data in an ini file be better than an include?
<?php class Constants{ const QUANTITY = 1; const EXAMPLE_CONST = "Blah blah blah"; } class ExtException extends Exception{ private $msg = "Gummy Bear"; public function __construct(){ $obj = new Constants(); $msg = Constants::QUANTITY . " " . $this->msg; parent::__construct($msg); } } try { throw new ExtException(); } catch(ExtException $e) { echo $e->getMessage(); } ?>
-
Need a little explanation. Read this snippet in a book. Exactly what is the author suggesting, storing all the constants in what type of file?
Thanks in advance
Were you to develop the MySQL classes further, you might end up with an unwieldy number of constants. In that case it would make sense to remove constant data members from their respective classes and store them in a file associated with the MySQLException class,
-
Thank you very much for the explanation makes sense
-
using the function filter_var with the constant FILTER_VALIDATE_EMAIL seems much easier, but a lot of books talks about using regular expression instead. Any opinions would be appreciated?
-
The class/book you have found is imposing an artificial restriction that is not present in the mysql_connection function they are claiming to mimic.
I read that section of the book soooo many times and it just kept confusing me. A BIG thank u for the clear explanation, now I can finally move on to the next section , hopefully there will not be any more confusing chapters later.
Thnx a whole bunch, it was driving me nuts.
-
Sounds like an incorrectly written class.
Thanks for explaining it in a very clear way, it was easily understood.
From what I gathered of what the author of the book is trying to teach, is that the reason he is suggesting to force one open connection at a time only, is mainly to conserve resources. TYPICALLY, does this resource concern justify the author's method, compared to just connecting to multiple dbases simultaneously?
-
Thank u for the explanation, it cleared things up a most of the way.
Another Question:
The example from the book is using a connection object, which uses a static variable to programmatically force it to only have one connection at a time. Is it that the main reason is to conserve resources, even though as stated by the above reply, where multiple connections is possible? (these books, sometimes when one keeps reading it over and over, it gets even more confusing)
See book excerpt below.
Book Excerpt:
Creating a database connection is an expensive operation so restricting creation of connections conserves resources.
By restricting the connection class to a single instance, we are mimicking the built-in mysql_connect function. Its default behavior is to reuse a connection resource rather than create a new one.
However, there are some circumstances where a new connection is a
necessity.
Two different connection objects are required if a single script needs to connect to two different servers. The close method makes it possible to connect to a different server.
Two instances of the MySQLConnect class can exist, but not simultaneously. If you want to create a connection to another server, you must first close the existing connection. The close method closes the current connection and resets the static variable $instances to 0. Manipulating the $instances variable in this way allows you to create a new connection, but only after the current one is closed.
-
Using a single script
Connecting to two dbases on different servers, must the first connection be closed first?
Connecting to two dbases on the same server, must the first connection be closed first?
-
it's centering fine as is with FF2, IE6 7 & 8. What browser r u using?
also, no need to use two separate declarations for the margin, just use
margin: auto; /*covers both left and right*/
-
using display:table has problems with certain browsers, especially with some IE
This is one of the better options for centering a floated list, personally, I prefer the first option on this page
-
If I link to a css file, and within that linked css file, it has 3 import css files
@import url(/css/1.css);
@import url(/css/2.css);
@import url(/css/3.css);
for the sake of argument, if each import file has the sale rule, but each with its own unique color
Is it correct that the last file "3.css" will override the first two, since that is the last of the import? Just like if using a single css, whatever comes last will override whatever is above it.
-
floated elements cannot be centered easily, there is a simple trick for it, read here http://pmob.co.uk/pob/centred-float.htm
-
if that fixes your problem and save you a big headache, and you still want to shoot some dough over that you don't want anymore, I sure can use it...
-
if this has to do with a:hover, the IE6 hover bug may require a trigger, like
a:hover { font-size: 100%; }
if font-size does not work, try color:whateverColor, or float:none, or border:none, and so on until you find one that works. The trigger point is different depending on how your overall code is. google for "ie6 hover bug".
-
our sales staff uses software that will only function on IE6
Pardon my French, than I guess you're f**ked. But, that's not a French word.
-
odd i clicked it and got nothing like that
can't be 100% sure, but that was the ONLY site (imagebam.com) I checked out that would even pull anything like that.
I google imagebam.com, found this on a yahoo group, happened to others also and imagebam also admitted it, guess it just depends on which ad you just happen to get on the page, and for me, I hit the lotto:
http://groups.google.com/group/imagebam/browse_thread/thread/bccf7410ea70bf49#
Clarification on creating an interface vs using a predefined interface
in PHP Coding Help
Posted
The following interface, because it starts with "interface", is that considered as a programmer defined interface, and not PHP's predefined interface? Book I am reading is getting me confused. Thank in advance