Jump to content

kicken

Gurus
  • Posts

    4,705
  • Joined

  • Last visited

  • Days Won

    179

Everything posted by kicken

  1. It's generally considered bad to override a method and change it's parameter signature. This is why PHP throws a strict standards warning if you do so. The reason behind this is that it makes the child classes incompatible with the parent, and thus they couldn't reliable be used with something that might written to specifications of the parent class. For example, what if you had some service that expects a ParentController object and tried called the doSomething() method. That code would assume that the function accepts an argument and does something with it. If you passed one of your child controller instances, the argument would be ignored. In your particular case this is not as much of an issue, but it's still a poor habit to get into. Think about if instead of reducing the parameter list you tried to extend it with non-optional parameters. Then the service would generate errors when calling the function because it didn't pass enough arguments. The better solution is to use an abstract (or empty implementation) method as the entry point which the child classes can then override. Any code that should be shared would then be moved out to another separate method which the children can then call when appropriate. <?php $controller=new ChildController1(); $controller->doSomething(); abstract class ParentController { abstract public function doSomething(); protected function doSomethingInternal($extra){ header('Content-Type: application/json;'); $id=(isset($_POST['id']))?$_POST['id']:0; $other=new otherclass(); $x=$other->bla($id,$extra); $flag=$x['flag']; unset($x['flag']); echo(json_encode($x)); return $flag; } } class ChildController1 extends ParentController { public function doSomething(){ if($this->doSomethingInternal('usethis1')){ $this->bla_a(); } } } class ChildController2 extends ParentController { public function doSomething(){ if($this->doSomethingInternal('usethis2')){ $this->bla_b(); } } } As also mentioned, if the pattern of 'if doSomething then bla();' is common across several children, you can move that up to the parent and just have the child classes override the bla method. Something like this: abstract class ParentController { abstract protected function getExtra(); public function success(){} public function failure(){} protected function doSomething(){ header('Content-Type: application/json;'); $id=(isset($_POST['id']))?$_POST['id']:0; $other=new otherclass(); $x=$other->bla($id,$this->getExtra()); $flag=$x['flag']; unset($x['flag']); echo(json_encode($x)); return $flag; } } class ChildController1 extends ParentController { protected function getExtra(){ return 'usethis1'; } public function success(){ //Rather than call a method, you'd just put your logic here directly $this->bla_a(); } } class ChildController2 extends ParentController { protected function getExtra(){ return 'usethis2'; } public function failure(){ //Rather than call a method, you'd just put your logic here directly $this->bla_b(); } }
  2. It depends on where the bottleneck is. If the problem is too much network traffic (which seems likely on a shared host) then there's not much you can do. If it's an issue of processing the results taking too long you may be able to speed it up by optimizing your code. Make sure your code is optimized so it will process results quickly. Do some benchmarks and profiling to determine where your code spends most of its time and see if there is any way to improve that area of code. Attempt to download different pages in parallel to make use of all the bandwidth you have available. You can do this with cURL and there are libraries available to make it easier.
  3. The "0": and "1": are there because you encoded an array-like object. Such json is perfectly valid, and would decode just fine with json_decode. You'll probably want to pass the $assoc flag as true so it decodes to an array rather than an object, that will make accessing things easier. $array = json_decode($json, true); var_dump($array[0], $array[1]);
  4. Just because your query will pull the course name for each row doesn't mean you have to display it in the output for each row however. As you process the query results in your code you can detect when the course name has changed and only display it at that point. Alternatively you can have your code group the results by course then output the results with some nested loops.
  5. If you want to try and re-implement a select box then you'll have to use Javascript to actually make it functional. You cannot re-create a working select box using just HTML and CSS. What exactly are you trying to accomplish?
  6. It's fine if you want to send a little money someone's way. If there isn't anything in their signature regarding donations/tips then a quick PM to them asking if they would accept a tip and via what means would be ok.
  7. I have no idea, never used it. Compile it and try it, probably wont take more than a few minutes.
  8. XDebug itself doesn't provide any kind of interface for actually interacting with the script. That is the job of a third-party client like your text editor or IDE. On the XDebug website they have a list of clients that will provide this functionality. In the list there is: If you're not using windows, then look at the list for other possible clients. If you feel comfortable with a compiler, the xdebug source package includes a simple client you can compile and use.
  9. Probably more likely is people debug with their IDE's but you said you don't want an IDE so there's not much to say. For step-through logic debugging I use PHPStorm with XDebug. For quicker informational debugging I just scatter some var_dumps around the code.
  10. Stupid forum and it's B) emoticon

    1. Show previous comments  1 more
    2. Irate

      Irate

      Totally agree.

    3. Philip

      Philip

      Consider it fixed!

    4. kicken

      kicken

      Woot! Awesome, thanks Philip

  11. Are you looking for code that will recurse down into all sub directories (and sub's of them and so on) or are you just wanting to find images from a specific subdirectory? If it's a specific sub directory, just pass it as part of the path, eg: foreach (glob('./images/*.png') as $filename) If you want a recursive setup you can look into RecursiveDirectoryIterator or scandir with a loop and stack.
  12. Naw, I generally don't care for it. Mostly that is just because of the implementations I've tried, almost all have sucked and gotten in the way more than they helped really. The only IDE I've used that I did like the completion for was Visual Studio when coding some VB.NET and C# stuff. It was pretty decent at completing structures like if's and loops while still being usable. It also provided suggestions for member functions and pressing enter/'.'/'(' would complete the word. I'm still used to just using my plain text editor without all the fancy ide features. I did pick up a copy of PHPStorm though and have been trying it whenever I work on something new. It's been pretty decent so far but I have a lot to learn about it still.
  13. You could also just boot into windows safe mode and delete the file. Mysql shouldn't be started up when you boot into safe mode.
  14. You could go the route of a web-based app also, I like SQL Buddy.
  15. Lots of people post really simple reviews like 'They worked great' or 'Support was good' without any particular evidence to back it up, same goes for negative reviews. Why are you being a hater on this guy/Linode? He did actually post a reason why he likes linode ("Their support crew helped me set up a redundant private network, even though I was on their most basic plan at the time!" aka They have good support). I happen to agree that Linode is one of the best companies I have used. One of my Linodes was poorly configured once and started eating up disk IO like crazy causing other nodes on that host to slow down. Rather than them just shut it down like some places would they sent me a nice email asking me to please reconfigure it to not use so many resources. Aside from wishing I could get more for less $$ (who doesn't?), I've no complaints with linode. Their services has been great, their control panel is fantastic and very easy to use, I've had 100% uptime, and the two times I've needed to talk to support they have responded promptly and courteously.
  16. Yea, my sisters and I used to play it a lot too as kids, particularly on road trips. We played #3 quite a bit too when we would go visit my grand parents, wasn't too much else to do over at their place besides play cards heh. Another game we played a lot that could be added to the list I suppose is the Triangle peg jump game. My grandpa had built his own board for it that we played on, was pretty neat. Triangle Peg Board Game
  17. Transplanted from one of my old Dev Shed post when someone asked for ideas: These were for a C++ programming course, but they could all be adapted for the web using PHP or Javasvript without too much issue. #4 is basically like the rpg already on the list.
  18. You can build up some more complex join conditions by using the join syntax. Aside from that though the main reason I prefer them is it keeps your join conditions separated from your where conditions and makes the query easier to read, especially when you get into some bigger more complex queries. For example SELECT sesuni.ADM_UN_ID as universityId, sesuni.ADM_UN_name as universityName, sescam.ADM_CAM_ID as campusId, sescam.ADM_CAM_name as campusName, ses.ADM_SES_ID as sessionId, ses.ADM_SES_name as sessionName, cat.ADM_CAT_ID as catalogId, cat.ADM_CAT_name as catalogName, sesoff.ADM_SES_OFF_ID as offeringId FROM session ses INNER JOIN academic_years sesay ON ses.ADM_SES_ADM_AY_ID=sesay.ADM_AY_ID INNER JOIN campus sescam ON sesay.ADM_AY_ADM_CAM_ID=sescam.ADM_CAM_ID INNER JOIN universities sesuni ON sescam.ADM_CAM_ADM_UN_ID=sesuni.ADM_UN_ID INNER JOIN session_offerings sesoff ON sesoff.ADM_SES_OFF_ADM_SES_ID=ses.ADM_SES_ID AND sesoff.DBODeleted=0 INNER JOIN catalog cat ON sesoff.ADM_SES_OFF_ADM_CAT_ID=cat.ADM_CAT_ID AND cat.DBODeleted=0 WHERE ses.DBODeleted=0 AND SYSUTCDATETIME() BETWEEN ses.ADM_SES_reg_start_date AND ses.ADM_SES_reg_end_date vs something like SELECT sesuni.ADM_UN_ID as universityId, sesuni.ADM_UN_name as universityName, sescam.ADM_CAM_ID as campusId, sescam.ADM_CAM_name as campusName, ses.ADM_SES_ID as sessionId, ses.ADM_SES_name as sessionName, cat.ADM_CAT_ID as catalogId, cat.ADM_CAT_name as catalogName, sesoff.ADM_SES_OFF_ID as offeringId FROM session ses, academic_years sesay, campus sescam, universities sesuni, session_offerings sesoff, catalog cat WHERE ses.ADM_SES_ADM_AY_ID=sesay.ADM_AY_ID AND sesay.ADM_AY_ADM_CAM_ID=sescam.ADM_CAM_ID AND sescam.ADM_CAM_ADM_UN_ID=sesuni.ADM_UN_ID AND sesoff.ADM_SES_OFF_ADM_SES_ID=ses.ADM_SES_ID AND sesoff.DBODeleted=0 AND sesoff.ADM_SES_OFF_ADM_CAT_ID=cat.ADM_CAT_ID AND cat.DBODeleted=0 AND ses.DBODeleted=0 AND SYSUTCDATETIME() BETWEEN ses.ADM_SES_reg_start_date AND ses.ADM_SES_reg_end_date In the first all the conditions related to how the tables join together are nicely separated and associated with their particular join. In the later it's all just one big mess in the where condition. That's actually a pretty simple and basic query compared to a lot of what I do each day.
  19. You could put them in either direction for the most part. I find it easier to conceptualize a query using left joins. I usually will have one table that would be considered the source table of the data, and another that has additional information. I make the source table the left and the additional table the right. For example, if I wanted a list of all students and their invoices I'd do: select * from students left join invoices on students.StudentId=invoices.InvoiceId As conceptually to me I want to first grab a list of all the students, then look into the invoices for any matching rows. Use which ever form makes the most sense to you though when your writing your queries.
  20. It's their position relative to the JOIN. FROM tableA JOIN tableB tableA is the left table tableB is the right table. When you specify LEFT, RIGHT, or INNER join it determines what happens when rows don't match up. For an INNER JOIN if a match can't be found in tableB for a row in table A then the row is dropped from the result set. Likewise only rows from tableB that match a row in tableA are kept, the others are dropped. For a LEFT join then all the rows from the LEFT table (tableA) are returned. If a matching row cannot be found in the right table, those columns are filled will NULL values. For a RIGHT join then all the rows from the RIGHT table (tableB) are returned. If a matching row cannot be found in the left table, those columns are filled with NULL values. There's also a CROSS JOIN where all the rows from both tables are kept. There's no condition for this type of join, each row from tableA is matched up to all rows in table B.
×
×
  • 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.