ignace
Moderators-
Posts
6,457 -
Joined
-
Last visited
-
Days Won
26
Everything posted by ignace
-
When I posted my example I was actually seeking for someone to concur or argument against my design - as there are quite some intelligent people around here (thorpe, CV, Daniel, Mchl, PFMaBisMad, ..) - not out to impress anyone. OO design is difficult, even more so if you have a low domain knowledge (like I have on micro-waves ). For example I doubt you would express the created energy in a micro-wave as temperature (the object inside heats up due to the generated energy) or that the wave intensity would be able to correlate to a simple float but being an example I thought "/care"
-
Here's my take on the subject which I believe has strong relations with the Observer pattern. interface Cookable { function changeTemperature(MicroWave $mw); } class BowlOfSoup implements Cookable { private $temperature = 0.0; // darn cold soup function changeTemperature(MicroWave $mw) { $this->temperature = $mw->getTemperature() * 1.267; } } class MicroWave { private $item = null; private $config = null; private $temperature = 0.0; function __construct() { $this->config = new MicroWaveConfig($this); } function insert(Cookable $item) { $this->item = $item; return $this->config; } function start() { for($i = 0; $i < $this->config->getCookTime(); ++$i) { $this->temperature = $i * 1.027; // on each second the temperature increases 2.7% $this->notifyTemperatureChanged(); } } function getCookedItem() { return $this->item; } function getTemperature() { return $this->temperature; } private function notifyTemperatureChanged() { $this->item->changeTemperature($this); } } 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; } function getWaveIntensity() { return $this->waveIntensity; } function setWaveIntensity($intense) { $this->waveIntensity = $intense; } function start() { $this->microWave->start(); } } $microWave = new MicroWave(); // spawn to World *MAGIC* $microWave->insert(new BowlOfSoup('Exquisite')) ->setCookTime(180)->setWaveIntensity(0.6)->start(); $soup = $microWave->getCookedItem();
-
@thorpe $food = new Food(); $food->setTemperature(25); Why do people still use micro-waves?
-
Reply: "Hey, that code you wrote to solve my problem doesn't work. Recheck it!" "why should I read the book when I have you blokes here to slove my problems." -- good point
-
Because it's the same. class SomeClass { private $data = array('hello', 'world'); function __toString() { return serialize($this); } function __sleep() { return array('data'); } } $c = new SomeClass(); echo serialize($c), ' ', $c, "<br>\n"; $s = serialize($c); $d = strval($c); var_dump(unserialize($s)); var_dump(unserialize($d));
-
That one. You also should add a __sleep() method to serialize your class data.
-
Could anyone give me some exercides / challenges?
ignace replied to Darkelve's topic in PHP Coding Help
For those in need of more challenge(s): $array = array(1, 2, 3); foreach($array as $k => &$v); foreach($array as $k => $v); print_r($array); // Output: ? -
Could anyone give me some exercides / challenges?
ignace replied to Darkelve's topic in PHP Coding Help
:: is called Scope Resolution operator or Paamayim Nekudotayim (Hebrew for double colon) and allows you to act upon static methods/constants/variables. The Object operator (->) allows you to call public non-static methods/variables. For those in need of another challenge: $a = 0; echo ~$a; // Output: ? -
Could anyone give me some exercides / challenges?
ignace replied to Darkelve's topic in PHP Coding Help
Hint: --> is not an operator on it's own -
PHP 6.0
-
Indeed, I like it too although I would have liked the "Image of the Week" return. The three boxes below the content on the homepage are amazing.
-
post your code!
-
I just noticed thorpe already added a simple example, here's mine: class User { function getAddressBook() { $addressBook = new AddressBook(); // ORM/DBAL operations foreach($this->db->fetchAll($sql) as $row) { $addressBook->add(new Address($row)); } return $addressBook; } } $user = UserFactory::makeUser($username, $password); $addressBook = $user->getAddressBook();
-
Problem on How to insert this to database
ignace replied to geekisthenewsexy's topic in PHP Coding Help
You need to add an AUTO_INCREMENT to the PRIMARY KEY column. -
I extended the regex to also support prune and prunelog. @(ban|prune|prunelog)\s(\w+) I doubt though this is the way to go as I keep thinking about how Linux finds/executes his commands and the similarities with your guestbook administration system. Basically each command would have it's own class which also would have knowledge about the user typing the command ($_SESSION) and an ACL to control whether or not they may execute that specific command. You may have for example @impersonate someUser which would be a privileged command for admins to make modifications to one's account or @login username password to log-in Basically you would be building your own IRC into your guestbook
-
echo ($refere && (stripos($r, $refere) === false)) && ($limited && ($line['hits'] >= $limited)) && !($pword && (isset($_POST['password']) && $_POST['password'] == $pword) && !($line['capt'] == 1 && ($_SESSION['security_code']) ? 'x' : 'gooooo'; LOOOLLLLL
-
Your choices should be based on knowledge/information not preference! If your row contains ONE timestamp it will update this one on each UPDATE regardless if you specified a value for it, the same applies for the first TIMESTAMP column if you have multiple such fields.
-
This isn't something complex: echo '<div style="float: left;">', "\n"; $i = 1; $total_per_column = 20; while($row = mysql_fetch_assoc($result)) { if(($i % $total_per_column) == 0) { echo '</div>', "\n", '<div style="float: left;">', "\n"; } // echo whatever you want it to look like ++$i; } echo '</div>'; It's adviced to calculate $total_per_column based on the result set (or limit the result set).
-
If thorpe keeps answering the questions like that I doubt he'll even reach 1/20
-
Maybe something like this? My idea being that you would want to display normal text in the shout box and hide commands. Each command will perform it's action on execute(). Bad commands for example can be seen by the one who typed it. CommandFactory::create($_POST['shout'])->execute(); class CommandFactory { static function create($shout) { if($shout[0] != '@') return new NullShout($shout); $args = str_word_count($shout, 1); $command = array_shift($command); $command = str_replace(' ', '', ucwords(str_replace('_', ' ', $shout))); return new $command($args); } }
-
HTTPRequest does not use the client's browser nor the server's. It uses the HTTP protocol to send it's message. Whose web filters? your companies? your schools? Downloading from Rapidshare are we? You realize that when caught with illegal material in a company/school you will have to call your lawyer?! Anyway, you don't need HTTPRequest. A simpe file_get_contens() will do to relay everything to the blocked site. echo file_get_contents('http://www.blockedsite.com/script.php?' . http_build_query($_GET));
-
Could anyone give me some exercides / challenges?
ignace replied to Darkelve's topic in PHP Coding Help
So 1h2 gets converted to 1 and then 3 is added. So the answer is: 4 That's correct I'm soon to be in need of more difficult riddles Ok, one before going to bed while($var --> 1); echo $var; -
Prevent other people from making PHP pages that POST to your forms?
ignace replied to php_guy's topic in PHP Coding Help
No. Sessions add state to HTTP not security. -
while($row = mysql_fetch_object($result)) { $keys[ ] = $row->id; $data[ $row->id ] = $row;}var_dump($data[ $keys[1] ]); // second row
-
POST YOUR CODE if you want help.