Jump to content

trq

Staff Alumni
  • Posts

    30,999
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by trq

  1. I should mention new lines don't matter, so... $microWave = new MicroWave(); // spawn to World *MAGIC* $microWave->insert(new BowlOfSoup()) ->setCookTime(180)->setWaveIntensity(0.6)->start(); could be.... $microWave = new MicroWave(); // spawn to World *MAGIC* $microWave ->insert(new BowlOfSoup()) ->setCookTime(180) ->setWaveIntensity(0.6) ->start(); or... $microWave = new MicroWave(); // spawn to World *MAGIC* $microWave->insert(new BowlOfSoup())->setCookTime(180)->setWaveIntensity(0.6)->start(); You can also so still call them the more traditional way.... $microWave->insert(new BowlOfSoup('Exquisite')) $microWave->setCookTime(180) $microWave->setWaveIntensity(0.6) $microWave->start(); but as you can see, chaining is a simpler (shorter) syntax. This stuff is just candy though, but allot of frameworks use it.
  2. If we fix ignaces example a little. class MicroWaveConfig { private $microWave = null; private $cookTime = 0; private $waveIntensity = 0.1; function __construct(MicroWave $mw) { $this->microWave = $mw; } function getCookTime() { return $this->microWave; } function setCookTime($cookTime) { $this->cookTime = $cookTime; return $this; } function getWaveIntensity() { return $this->waveIntensity; } function setWaveIntensity($intense) { $this->waveIntensity = $intense; return $this; } function start() { $this->microWave->start(); } } You can now chain these methods together.... $microWave = new MicroWave(); // spawn to World *MAGIC* $microWave->insert(new BowlOfSoup()) ->setCookTime(180)->setWaveIntensity(0.6)->start(); because each of the methods returns the MicroWaveConfig object.
  3. I think ignace might have simply got a little rushed at the end of his example. The design itself is allot better than mine and mimics the real world allot closer. I always have trouble finding the pattern top fit the problem, but I was also trying to keep it pretty simple. Your right, this arument being passed to the __construct() isn't being used in this example. Not really, he is chaining the methods together. See my next response though.... You can chain methods together like that. However, each of the methods need to actually return $this. In this case they don't so it wouldn't work, but the idea is good.
  4. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=311502.0
  5. There's a good free book/wiki (Hudzilla) in my signature, I think its also available in print. Because Dreamweaver (or any IDE / Tool for that matter) can't actually think like humans can and programming involves quit a bit of decision making. Dreamweaver has to write code to cover all basses, which often leads to allot of unnecessary and convoluted code.
  6. You have a point. Like I said, I was in a rush
  7. Hello hype_rain and welcome to the boards, I wouldn't bother with any PHP for Dreamweaver books for PHP. Dreamweaver writes some of the worst PHP code around and besides, you really should learn the language itself, not just how to have Dreamweaver produce code for you. You can still use Dreamweaver as your editor though.
  8. This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=311501.0
  9. Variables are not interpolated within single quotes. $PassWord = "<font color=\"red\">" . MD5('$_POST[PassWord]'). "<br/></font>"; should be.... $PassWord = "<font color=\"red\">" . MD5($_POST['PassWord']). "<br/></font>";
  10. Oh, one more quick thing. I think your naming your methods too specifically. eg; There is no point having a methods called getSoupTemperature() within a soup object, getTemperature() should suffice.
  11. Iv'e only had a really quick look (I'm at work), but you seem to be on the right track. One thing I would do however is make a base 'Food' class. Bowls can hold more than just soup so there is no point locking a bowl into only being able to hold soup. From there you would make your Soup class extend food. Because a 'type' might not belong to all foods, you should keep that within Soup, just put the generic stuff in 'Food'. You might have a bowl of 'porridge' for instance (I know, you can get different flavours/types of porridge these day, I'm just trying to point out that you put the more generic stuff in the food class and extend it with the more specific stuff). So your code might look more like.... class Food { private $type; private $temperature; public function __construct($t=null){ $this->type = $t; } public function setTemperature($temp=null){ $this->temperature = $temp; } public function getTemperature(){ return $this->temperature; } } class Soup extends Food { public function getType() { return $this->type; } } While the FillBowl() method now excepts Food. public function fillBowl(Food $s){ $this->contents = $s; } You should be able to do much the same with the Bowl object given that, you can also put plates, lunch boxes, cups etc etc in a microwave. Doing this (as I'm sure you understand) suddenly makes you classes allot more flexible.
  12. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=311492.0
  13. We are going to need more details I think. Can we see some code? Putting it simply though, the Soup object would need a method that sets its temperature.
  14. You cannot get a value from a variable that hasn't been defined yet.
  15. You don't need to make a separate script, just make sure you supply the full path to mysqldump, or set the PATH variable. 15 2 * * * /usr/bin/mysqldump --user root --password="passowrd" --opt database_name > /home/myrefco/db/db-`date +%Y-%m-%d`.sql
  16. RewriteLog needs to go within either your main httpd.conf file or your vhost config. It cannot be placed within a .htaccess file.
  17. There are lots of different uses for multiple IP addresses. The first probably being that I would use a dedicated IP address for ssh access, another dedicated to standard web. This way you can have only the ports required to be open on there corrisponding ip's. SSL also comes to mind. While there is now progress being made with ways to host multiple SSL certs on a single IP address, it is still general practice to have one cert per IP (and may still be the only way to do it, I haven't actually looked into this for a long while). In short, I would be inclined to use one IP for admin purposes. ssh, svn, ftp access etc etc, another for public web, and keep the other for the case where your running multiple sites.
  18. I'm not sure I understand. SELECT queries are used to retrieve data, why would selecting zero data be valid?
  19. So, your saying if you execute a SELECT that returns no records you don't display an error message or something? I would, ALWAYS. The easiest way is to check to see how many results you got.
  20. This line.... LoadModule gzip_module modules/mod_gzip.so tries to load an so file, windows uses dll's.
  21. ob_start(); // your code would go here. echo "outputted from code"; $str = ob_get_contents(); $str would now hold the output of all code between ob_start() & ob_get_contents().
  22. It gives you the opertunity to display a message if no records are found.
  23. Except that you should always check your query actually returns a result before using it. A typical SELECT query should pretty much look like.... $sql = "SELECT foo FROM bar"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_assoc($result)) { // use row } } else { // no result found } } else { // query failed } A while loop is generally better than a foreach in such a case, but if you only expect 1 row, you should use a LIMIT clause in your query and obviously can leave the while loop out all together.
  24. This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=311333.0
×
×
  • 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.