Jump to content

requinix

Administrators
  • Posts

    15,053
  • Joined

  • Last visited

  • Days Won

    413

Everything posted by requinix

  1. Just use a normal, plain, simple function. Like in your first example. OOP is about object entities, not about using classes for everything. The reason it doesn't work is because the "Log" that you are use-ing in Main.php does not apply to functions.php too. It's a per-file thing. So //functions.php use Company\Project\Handlers\Log; function __log_notice(string $text) { Log::notice(0, $text, true); }or //functions.php function __log_notice(string $text) { Company\Project\Handlers\Log::notice(0, $text, true); }
  2. Are you the owner of the account? Do you know what I did with the account? I made a quick post to let other mods/admins know the OP's request had been addressed. It's not like I can contact the person or they can reply to threads... Not being able to delete one's own account is normal. I know of, like, two websites which let you do that. Or at least claim that you're doing that - I would be surprised how many of them actually remove account data from their systems. Because record-keeping is actually very important. Re: flippant. Yeah, I see that. I tend to react to rude comments and snideness similarly. I've also not been in a good mood lately because of, you know, this whole shitstorm. Re: you don't remember signing up. It's only been 2.5 years and you have more than a dozen posts across three threads spanning half a month. But whatever. Do you want your account suspended too? If you were using your real name or a personal email address then I would have offered to sanitize it along the way (no offense if that is, in fact, your first name, which would be kinda cool).
  3. 30 days of elapsed time or 30 days on the calendar? There is a difference. Are you using times with the dates too? And most importantly, what code do you have written so far and what kind of problems are you having with it? That is no excuse. I'm a fan of those functions too, but there are some things DateTime can do better. Depends how you store the date. The only two good options are as a DATE/TIME/DATETIME or as a Unix timestamp (which would use an INT or larger). For the former you just create a string in the "YYYY-MM-DD HH:MM:SS" format (eg, Y-m-d H:i:s), for the latter you keep the integer values that functions like time() and mktime() and strtotime() return.
  4. Really? You can't remember to type mywebsite.com so you're looking for a technological solution? How about a bookmark? Takes seconds to make one and you, who has a problem typing things, can instead click things instead. The hosts file is what you're thinking of, but it alone won't be enough. All it does is tell your browser which server a website lives at. It doesn't do redirects. Odds are you will have to configure the server that hosts mywebsite.com to be able to handle "my.ebay.com", and then have it issue the redirect. Because there is no way to have a client-side redirect before you've even gone anywhere - unless you make an add-on or extension for your browser.
  5. For all the files, you'll need another loop: use glob to get the list of files you want, foreach over it as $source, and then put that code you have to load a file into it. Dealing with un-namespaced XML elements (like ) is easy: do what you're doing now. Dealing with namespaced elements (like ) takes a bit more work. To do something like ->video:title, which you can't do for a couple different reasons, you need to use ::children. const XMLNS_VIDEO = "http://www.google.com/schemas/sitemap-video/1.0"; // <urlset xmlns:video="..."> echo $url->children(XMLNS_VIDEO)->video->title;Explanation? When you do ->video, SimpleXML will try to find a and won't find it. When you use children() first, SimpleXML will look for the namespace using that URI (an xmlns:video), figure out what XML namespace prefix to use ("video:"), and then begin looking for elements in that namespace. $url->video->title // <title> inside <video> inside $url $url->video->children(XMLNS_VIDEO)->title // <video:title> inside <video> inside $url $url->children(XMLNS_VIDEO)->video->title // <video:title> inside <video:video> inside $url
  6. Have you tried SimpleXML yet? Written any code so far?
  7. First, use an array for the decoded JSON. Having to use that {""} syntax is unfortunate and awkward. $zooelements = json_decode($elements, true); $name = $zooelements["0ad767cantbebotheredtocopypaste"][0]["value"];Second, are you actually using a @ when you call mysql_query? That will hide any errors that may happen. Hiding errors is very bad. Don't use @. Is your question about how to update $zooelements? Surely the answer is just $zooelements["0adblahblahblah"][0]["value"] = "NameEFGH";
  8. How can you make the checkbox be checked for the user? Put a "checked" in the HTML if you want it checked. There's something funky happening with your code in that form, so I'm going to go out on a limb and fix it. />The value doesn't really matter, and instead it uses the value in $result to show the "checked" or not.
  9. "Get function"? And for two, your form is using POST and not GET. Those textboxes and checkboxes have names, right? Like "water-purveyor" and "v1-na". So those will be in $_POST - though checkboxes only if the user checked them, so you need isset() for those. $water_purveyor = $_POST["water-purveyor"]; $v1_na = (isset($_POST["v1-na"]) ? $_POST["v1-na"] : /* default value? */ null);
  10. That code? You're throwing an exception only to catch it on the next line. That's pointless. You might as well just public function indexAction(Request $request) { if(!is_object($request)) { $this->logger = $this->get('logger'); $this->logger->info("You have the following error: { $error }", array("error" => "Param must be an object")); } }By the way, inconsistent indentation drives me crazy. I'm trying not to go into a treatise about how exceptions are supposed to work (too much to say that has been said elsewhere on the internet), with mixed success, but basically you use them if there is something unexpected that happens and your code is not able or supposed to handle it. Look around to see what people say about how to use exceptions - even if it applies to other languages (notably Java and C#). First of all, in your situation $request is going to be an object because you used the typehint. Not that it will prevent someone from calling the method with a non-Request or non-object, but if they did then there will be an error about it and your logger will see that (assuming your logger is set up for PHP errors, which it should be). If you still want exceptions here then I'd use something more like public function indexAction(Request $request) { if (!($request instanceof Request)) { throw new InvalidArgumentException('$request must be a Request object'); }The main point here is that indexAction cannot recover from this problem. There is nothing it can do. The Exception "forces" someone in the call stack to handle an InvalidArgumentException - or worst case nobody does and PHP fatals. Also note the InvalidArgumentException instead of just Exception. Pretty much every sort of exception you'd want to throw really, really needs to be a subclass. Throwing Exception everywhere severely limits what you can do when catching them: (a) You would have to resort to crazy hacks to figure out what kind of problem it represents, but more critically (b) You'll catch and handle types of circumstances your code isn't prepared for. If you set up a try/catch because you know that (eg) the function you're calling can error because a file doesn't exist, you'll get that, but you'll get every other exception too. And if you discard the exception because the missing file isn't a big problem, you're now discarding every exception. The InvalidArgumentException class specifically indicates that there was a problem with an argument to a function. I don't ever catch this class[1] because it represents a fundamental problem with the code itself - not merely some sort of unexpected situation or unusual circumstance. Continuing that train of thought, only catch the exceptions you want to handle. If something can throw an exception but your code doesn't know what to do in that case, don't catch it there. Instead, go backwards up the call stack until you find a place where it makes sense. Common example: set up a try/catch just before you try to "execute" the code for a particular page on your site, then in case of an exception you can (log it and) show an error message to the user. So public function indexAction(Request $request) { // do whatever public static function /* Controller:: */ invokeAction($controllerClass, $action) { $controller = new $controllerClass(); $method = $action . "Action"; $request = Request::current(); // no try/catch because there isn't any type of exception this method is prepared to handle $controller->$method($request); } try { Controller::invokeAction($controllerClass, $action); } // one type of exception that you want to use special handling for catch (SomeParticularTypeOfException1 $e1) { // ... } // another type of exception with special handling catch (SomeOtherTypeOfException2 $e2) { // ... } // catch every other exception so we can present an error message to the user catch (Exception $e) { ErrorController::showErrorPage(500, $e); // public static function showErrorPage($code, Exception $error = null) }[1] Unless I'm working with a system that must not fail[2], I do this. Which is to say I have a logger set up for uncaught Exceptions, log their presence, then let PHP die.[2] Well, that or there's a chokepoint in the code where I want to wrap any exceptions caught inside another exception. In which case I use the "$previous" parameter to Exception, like try { callSomeFunction(); } catch (Exception $e) { throw new BadMethodCallException("callSomeFunction failed: " . $e->getMessage(), 0, $e); }Side note: make sure your logger can handle nested exceptions.
  11. Variables defined outside of functions are not available inside of functions. Pass what you need as arguments, like function output($connection, $sql) {
  12. That was addressed to me, right? I'm not sure what you mean. I'm talking about four functions that look like /** * @param string $filename * @param array $variables * @return mixed */ function include_once_clean() { if (func_num_args() > 1) { extract(func_get_arg(1)); } return include_once(func_get_arg(0)); }and include_once_clean("/path/to/file"); include_once_clean("/path/to/file", ["var" => "value"]); What?
  13. It's not negligible but if you need a wrapper for something like logging then it's probably worth it. I have my own wrappers which I use to make sure files are run in a new scope - no inherited variables and whatnot.
  14. If you entered it into the website then we have it. Not rocket science.
  15. Adding code to a system increases the likelihood of there being bugs? You don't say! This is IPB 3. Sorry that the theme looks too nice.
  16. Posting something so I can mark this as solved.
  17. Is there a problem with prompting the user for which site to use? For example, what UPS and FexEx do. There's a pretty substantial advantage to prompting in that the user controls which site they use. With that said, defaulting and then offering a way to switch shouldn't be too bad. Otherwise what you're looking for is generically called geolocation.
  18. elfynity, your account is suspended and will no longer work. erilidon, sorry you don't like the policies you agreed to, but fortunately they will no longer be an issue for you as I've done the same for your account.
  19. We don't like deleting accounts, but I can "suspend" you so your account is no longer active.
  20. Empty for me too. I don't know why Opera is downloading it. There's nothing indicating it should be downloaded. Can you see what the request and response headers are for it?
  21. I'm going to start suspending accounts for people who ask for it. mrbraq, rpoelking, darkcarnival: I'll suspend yours tomorrow (to give you time to see this post).
  22. If you see them again, try to get the full URL to the ad. We can then submit it to our advertisers who can do something from there.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.