NotionCommotion
Members-
Posts
2,446 -
Joined
-
Last visited
-
Days Won
10
Everything posted by NotionCommotion
-
Do exceptions span all functions and methods?
NotionCommotion replied to NotionCommotion's topic in PHP Coding Help
Just spent the last hour teaching algebra to my 11 year old daughter. I'm going to call it a pattern Whoah, I looked in the manual, and this the "FileOpenException" definitely doesn't exist! So, could one could just willynilly make up exceptions for what ever one wishes? I hope so, and guess this is the crux of my question. -
Do exceptions span all functions and methods?
NotionCommotion replied to NotionCommotion's topic in PHP Coding Help
I have never used finally. Is it an often used pattern that I should probably be using more often? Do you have any thoughts about inserting a business exception in between PDO exceptions, and dealing with them similarly, yet letting other exceptions remain uncaught? -
Do exceptions span all functions and methods?
NotionCommotion replied to NotionCommotion's topic in PHP Coding Help
Try it: Agree. Nice pun Transactions: Most of my reasons for these questions were driven by trying to implement transactions. One tries three sequential queries, and one fails, so you catch the (PDO) exception and roll it back. Do I have this right? But what if there was some business logic in the mix? Could I throw an exception so it is rolled back just as if it was a PDO exception? -
Include external file in ebay listing.
NotionCommotion replied to QuizToon's topic in PHP Coding Help
Thanks and understood. But you agree using include() on a URL (even with wrappers) is likely never a good idea? -
Do exceptions span all functions and methods?
NotionCommotion replied to NotionCommotion's topic in PHP Coding Help
Gotcha, So what if I wanted to try something, and catch any for example PDOexception plus any exception I throw in my script, and deal with them in the same manner (i.e. delete any inserted records, etc)? Could I have multiple catch statements, and if so are they executed in sequence and only perform the first match? On a side note (sorry for asking more), are local variables in my try statement available in my catch? try { $bla=123; db::db()->exec('some bad SQL'); if($bad) {throw new Exception('bla bla.');} } catch (PDOException $e) {echo('deal with SQL exceptions and do the same thing '.$bla);} catch (Exception $e) {echo('deal with script thrown exceptions and do the same thing. '$bla);} -
Do exceptions span all functions and methods?
NotionCommotion replied to NotionCommotion's topic in PHP Coding Help
Thank you Jacques, Could you elaborate on "Never catch the top-level Exception class, only specific subclasses"? If you mean let the default error handler deal with them, I understand (but didn't 30 days ago), but if something else, please advise. Thanks -
Will an uncaught exception in any of the child methods percolate up? Same thing for functions? Thank you. <?php class bla { function bla() { try { if($bad) {throw new Exception('bla bla.');} $this->something_else_that_might_throw_an_uncaught_exception(); } catch (Exception $e) {echo('do something to deal with the exception');} } function something_else_that_might_throw_an_uncaught_exception(){ $this->even_something_else_that_might_throw_an_uncaught_exception(); } } ?>
-
Include external file in ebay listing.
NotionCommotion replied to QuizToon's topic in PHP Coding Help
Another option is include() per http://php.net/manual/en/function.include.php. Bad idea? I would expect file_get_contents() is typically the best choice. -
I suppose this is the right place and if you asked how to send specific values using cURL, people can help you, but no one knows the Roblox API or protocol and how to interface it to PHP, and likely doesn't want to learn it. If you can figure out how Roblox/Lua interfaces to PHP and specify what values must be sent via cURL, we can likely help. Maybe some specific Roblox specific forum could help the first part? You could also try to hire someone via Odesk or something, but I would be very cautions letting anyone access your server that you don't know and trust.
-
Include external file in ebay listing.
NotionCommotion replied to QuizToon's topic in PHP Coding Help
I've never used a URL with include. Appears to work provided you have the appropriate wrappers. That being said, I would highly recommend not doing so, and store it locally, or use curl if it really needs to be remote. I would be interested in other opinions. Warning: include(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in /var/www/main/html/testing/include.php on line 2 Warning: include(http://php.net/manual/en/function.include.php): failed to open stream: no suitable wrapper could be found in /var/www/main/html/testing/include.php on line 2 Warning: include(): Failed opening 'http://php.net/manual/en/function.include.php' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/main/html/testing/include.php on line 2 -
Hi quickoldcar, I am using the jQuery validation plugin, so most if not all of the errors are caught before going serverside, and show a message next to the field. I never looked into html5 validation before, but just did at http://www.the-art-of-web.com/html/html5-form-validation/. Wow, not much need to implement a preliminary JS validation strategy any more, is there? You think most user's browsers support nowadays? Not sure I understand the "call a friend" feature.
-
Ugg, I used: $config = HTMLPurifier_Conf::createDefault(); And should have been using: $config = HTMLPurifier_Config::createDefault(); With the static functions and autoclasses, it was not very obvious. Other than attention to detail, are there any other takeaways? Are there better ways to troubleshoot this scenario? In regards to "HTMLPurifier_Bootstrap::registerAutoload seems needlessly complex", it is not mine, but the script which comes with http://htmlpurifier.org/. Thank you for your help!
-
Hey Kicken, Don't know and don't think so. Auto loader functions are on my list to get better on. As the autoload object/array seems to get modified in multiple places, is it possible to display the current settings at any given moment in time? PS. Thank you very much. This has got me stumped.
-
Unfortunately for me, the following script runs without errors. Like in my application, it uses the autoload_register with the true,true arguments, but finds the static class. What would make one scenario find the correct class, yet not the others? I am not expecting a definitive answer (but give one if you have one!), but a process to troubleshoot. Thank you <?php require_once ('../../application/classes_3rd/PHPMailer/PHPMailerAutoload.php'); class myPHPMailer extends PHPMailer { public function __construct($allow_exceptions=false){ $this->isSMTP(); $this->SMTPDebug = 0; $this->Debugoutput = 'html'; $this->Host = "smtp.gmail.com"; $this->Port = 587; $this->SMTPSecure=true; $this->SMTPAuth = "tls"; $this->Username = "fu"; $this->Password = "bar"; } } $mail = new myPHPMailer(); $mail->AddReplyTo('x@x.com','x'); $mail->SetFrom('y@y.com','y'); $mail->Subject = 'Hi'; require_once '../../application/classes_3rd/htmlpurifier/library/HTMLPurifier.auto.php'; $config = HTMLPurifier_Config::createDefault(); $purifier = new HTMLPurifier($config); $dirty_html='<bla>Bad</bla><p>Good</p>'; $clean_html = $purifier->purify($dirty_html); echo($clean_html); ?>
-
Okay, I have a clue. I used the same two lines of code both in my application, and just all by themselves: require_once('/var/www/bidjunction/application/classes_3rd/htmlpurifier/library/HTMLPurifier.auto.php'); $config = HTMLPurifier_Conf::createDefault(); They work when by them self. The only difference than I could see is in HTMLPurifier_Bootstrap::registerAutoload(). public static function registerAutoload() { $autoload = array('HTMLPurifier_Bootstrap', 'autoload'); if (($funcs = spl_autoload_functions()) === false) { spl_autoload_register($autoload); } elseif (function_exists('spl_autoload_unregister')) { if (version_compare(PHP_VERSION, '5.3.0', '>=')) { // prepend flag exists, no need for shenanigans spl_autoload_register($autoload, true, true); } else { //something else } } } When running by themselves, the first IF statement is true, and spl_autoload_register($autoload); is executed. When running in my application, the first IF statement is false, and the next ELSEIF and following IF statement is true, and spl_autoload_register($autoload, true, true); is executed. What does this mean, and why the dramatic difference in behavior? I am okay with no specific answer, but just another mission to investigate. Thank you
-
I have a form on a user input page in an application which requires JavaScript. Please keep whether one should require JavaScript off the table. I have two possible workflows: Option 1 Display form either with no filled in inputs if it is a new entry, or existing data from the database should it be an edit. Upon submit, validate the page client side and if okay post the data via Ajax. Server validates the data, saves data if no errors, and returns an array with any errors. Client alerts (probably with an alert statement) user of any errors and if none redirects client side to the next appropriate page. Option 2 Display form either with no filled in inputs if it is a new entry, or existing data from the database should it be an edit. Upon submit, validate the page client side and if okay submits the form. Server validates the data. If no errors, saves the data and redirects to the next appropriate page. If errors, redisplay the page with appropriate errors and makes previous user inputs sticky. I previously went with Option 1, but started to think it was a bit of a kludge. Sure is easy to implement, however. Are there any other recommended workflows? Is one of these two options better than the other? Thank you
-
Thanks hansford. I could post all the code, but was afraid I would be overwhelming. And while I previously thought code wasn't magic, no longer am so sure Thanks kicken, you gave me at least a mission to find out why `HTMLPurifier_Conf` isn't defined. Maybe it isn't magic after all!
-
Please help. I have tried to condense the following code to make it easier for someone to shed insight. The results make totally no sense to me. I have the following two lines of code: require_once('/var/www/bidjunction/application/classes_3rd/htmlpurifier/library/HTMLPurifier.auto.php'); $config = HTMLPurifier_Conf::createDefault(); Let me explain what happens in these two lines of code. First.... require_once('/var/www/bidjunction/application/classes_3rd/htmlpurifier/library/HTMLPurifier.auto.php'): HTMLPurifier.auto.php is shown below: <?php /** * This is a stub include that automatically configures the include path. */ set_include_path(dirname(__FILE__) . PATH_SEPARATOR . get_include_path() ); require_once 'HTMLPurifier/Bootstrap.php'; require_once 'HTMLPurifier.autoload.php'; // vim: et sw=4 sts=4 The only thing Bootstrap.php does is define a class and execute the following line: define('HTMLPURIFIER_PREFIX', realpath(dirname(__FILE__) . '/..')); The only thing HTMLPurifier.autoload.php does is execute HTMLPurifier_Bootstrap::registerAutoload() (which was one of the classes defined in Bootstrap.php). The only thing HTMLPurifier_Bootstrap::registerAutoload() does is: spl_autoload_register(array('HTMLPurifier_Bootstrap','autoload'), true, true); Now the second line: $config = HTMLPurifier_Conf::createDefault(); I expected that HTMLPurifier_Conf::createDefault() would be executed, but no, instead the script goes to HTMLPurifier_Bootstrap:autoload() which returns false. Next, the script goes to function PHPMailerAutoload() which is in PHPMailerAutoload.php. What!!! What does PHPMailerAutoload have to do with this? While a perfect answer would be great, general comments and a strategy to troubleshoot be the next best thing. I am stumped! Please help.
-
Is this a stupid use for static properties?
NotionCommotion replied to NotionCommotion's topic in Application Design
Thanks ignace, Yes, I agree I was given examples of best practice. Regarding "why", I understand a static shouldn't be be because: Colleagues will frown upon your use of static anything. Is a bit weird. Couples your code to a specific implementation and makes it harder to change later on. Harder to troubleshoot. I could live with #1 and #2. As for #3 and #4, why is it harder to change later on or troubleshoot? We have other super variables like $_SERVER which contain specific values based on the given state, and don't have problems. I know many on this site are much more knowledgeable and experienced than me, and I should probably just let this go... -
I have a bunch of quasi-static values that must be available to the application. Most of them are set based on settings in a configuration file. Others are based on GET, COOKIE, or SESSION values, and utilize the database to get the actual values. The values will never be written to or modified by the application, only read. It seems to me that I could create some sort of superclass which includes static methods and properties, and I could access any value by something like superclass::get('some.value'); I could design the class so that the values are queried from the DB or obtained from a parsed file only the first time they are requested, and for future requests, retrieved from a static property. That being said, I have been told from more than one person that I am just doing it "wrong". Please let me know what is wrong about it. Thank you
-
What are BSD Sockets used for?
NotionCommotion replied to NotionCommotion's topic in Application Design
Thanks kicken, Your examples helped. If I understand things correctly, PHP is being used to implement a protocol? When would one elect to build some lower level language driver (sorry that is probably a windows term) to bridge protocols? -
What about this? $encoder = new Base2n(5, '0123456789ABCDEFGHJKMNPQRSTVWXYZ'); $raw_token = mcrypt_create_iv(16, MCRYPT_DEV_URANDOM); $activation_code = $encoder->encode($raw_token);
-
Newbie - where to store MYSQL connection name/password
NotionCommotion replied to enveetee's topic in PHP Coding Help
Well, I can tell you not to store it at /var/www/html/mySecretPasswords.ini (assuming a Redhat install). I wouldn't even do so if protected by .htaccess or something similar in httpd.conf as it is just a desultory in waiting. I've toyed with the idea of encrypting the file, but since PHP will need to decrypt it, I guess this doesn't make sense. -
What are BSD Sockets used for?
NotionCommotion replied to NotionCommotion's topic in Application Design
While not in those exact words, yes, that is exactly what I asked. My uncertainty is what circumstances would I be forced to use them. Without writing a book, could you give a couple good examples of "lots of stuff"? I don't think I have any immediate needs, but without knowing what is possible, don't know for sure. Thank you -
What are BSD Sockets used for?
NotionCommotion replied to NotionCommotion's topic in Application Design
Thanks Requinix, Your explanation was helpful. But why would I want to use the explicit PHP socket functions? I would assume any standard communication interfaces which PHP supports implements sockets under the hood using a lower level language. I could see using these functions if implementing a propitiatory interface or some interface which PHP doesn't natively support. Are these the only reasons, or are there others? And of course wishing all a happy New Year!