Daniel0
Staff Alumni-
Posts
11,885 -
Joined
-
Last visited
Everything posted by Daniel0
-
Code from scratch or use an existing toolkit?
Daniel0 replied to kendhal's topic in Application Design
This doesn't sound particularly complicated, so coding it from scratch wouldn't be a problem in this instance. -
Whether you used persistent connections or not wouldn't matter in this case. You'd still have to explicitly call the connect function anyways which means that the __wakeup() method would have to be called because the resource in the variable would be gone.
-
Which country do you live in?
-
That's just type hinting. It's covered in the manual which I suppose everybody dealing with PHP has read. http://www.php.net/manual/en/language.oop5.typehinting.php
-
First of all, PHP functions are case-insensitive, so whether he does mysql_Query() or mysql_query() doesn't matter. The reason why it isn't working is because that function returns a resource, so when you print it to the screen it will show the resource id. To get the actual results of a query you'll have to one of the mysql_fetch_*() functions.
-
What are the expected and actual results?
-
When I installed Safari I opted to not have their updating software installed. I remembered it as being quite intrusive and extremely annoying.
-
It means that scripts using legacy extensions for database connectivity will not work with default PHP6 installations. This can be solved by using PDO or by installing the extensions from PECL. Using PDO also has the benefit of being easily able to switch between various DMBS as long as you're not using vendor specific SQL.
-
I don't know if you're one of the people I've discussed the usage of singletons with, but this clearly shows how unneeded usage of the singleton pattern can transform from what seemed to be a convenience to an inconvenience. As you have uncovered yourself, the usage of a singleton has coupled your classes too tightly. Had your "base class" accepted an instance of url_helper passed to it by argument and ensured that it was an url_helper instance by using type hinting, then a child class (e.g. something like my_url_helper like I said above) would have been compatible with your framework/base class. For solving your problem, you could classes which would take an instance of url_helper and use url_helper::get_links() or whatever to generate the breadcrumbs or some other kind of extended functionality based on that of url_helper.
-
Yes it is. Also, all the vendor specific extensions (mysql, mysqli, pgsql, etc.) are going to be moved be moved to PECL in PHP6 while PDO remains installed by default.
-
There is much more to OOP than just using objects/classes. It's not comparable to using a function library.
-
In that case, why couldn't the user of your framework not just extend the url_helper class? <?php class my_url_helper extends url_helper { function get_breadcrumbs() {} } ?>
-
Use SimpleXML. <?php $rss = new SimpleXMLElement('http://www.phpfreaks.com/forums/index.php?type=rss;action=.xml', null, true); echo "<ul>\n"; foreach ($rss->channel->item as $item) { echo "\t<li><a href='{$item->link}'>{$item->title}</a></li>\n"; } echo '</ul>'; ?> Output (currently): <ul> <li><a href='http://www.phpfreaks.com/forums/index.php/topic,188668.msg846635.html#msg846635'>Re: Backup Restore time-out</a></li> <li><a href='http://www.phpfreaks.com/forums/index.php/topic,188305.msg846634.html#msg846634'>Re: Different OO JavaScipt approaches: please advise</a></li> <li><a href='http://www.phpfreaks.com/forums/index.php/topic,188794.msg846633.html#msg846633'>Re: Updating some text every few seconds</a></li> <li><a href='http://www.phpfreaks.com/forums/index.php/topic,188734.msg846632.html#msg846632'>Re: Hooks?</a></li> <li><a href='http://www.phpfreaks.com/forums/index.php/topic,188798.msg846631.html#msg846631'>How to parse RSS...</a></li> </ul>
-
Check out the observer pattern. Something like this: <?php class SomeClass { const STATUS_ZERO = 0; const STATUS_ONE = 1; const STATUS_TWO = 2; private $observers = array(); private $status; public function __construct() { $this->status = self::STATUS_ZERO; } public function getStatus() { return $this->status; } public function attach(SomeClass_Observer $observer) { if (!in_array($observer, $this->observers)) { $this->observers[] = $observer; } return $this; } public function detach(SomeClass_Observer $observer) { $numObservers = count($observers); for ($i = 0; $i <= $numObservers; $i++) { if ($this->observers[$i] === $observer) { unset($this->observers[$i]); break; } } return $this; } private function notify() { foreach ($this->observers as $observer) { $observer->hook($this); } } public function doSomething() { echo 'do something in ' . __METHOD__ . '()' . PHP_EOL; $this->status = self::STATUS_ONE; $this->notify(); echo 'do something else in ' . __METHOD__ . '()' . PHP_EOL; $this->status = self::STATUS_TWO; $this->notify(); } } interface SomeClass_Observer { public function hook(SomeClass $someClass); } class SomeClass_Observer_AnObserver implements SomeClass_Observer { public function hook(SomeClass $someClass) { switch ($someClass->getStatus()) { case SomeClass::STATUS_ONE: echo '[status 1] doing something in ' . __METHOD__ . '()' . PHP_EOL; break; case SomeClass::STATUS_TWO: echo '[status 2] doing something else in ' . __METHOD__ . '()' . PHP_EOL; break; } } } class SomeClass_Observer_AnotherObserver implements SomeClass_Observer { public function hook(SomeClass $someClass) { if ($someClass->getStatus() == SomeClass::STATUS_ONE) { echo '[status 1] doing something in ' . __METHOD__ . '()' . PHP_EOL; } } } $someClass = new SomeClass(); $someClass->attach(new SomeClass_Observer_AnObserver()) ->attach(new SomeClass_Observer_AnotherObserver()); $someClass->doSomething(); ?> Output: do something in SomeClass::doSomething() [status 1] doing something in SomeClass_Observer_AnObserver::hook() [status 1] doing something in SomeClass_Observer_AnotherObserver::hook() do something else in SomeClass::doSomething() [status 2] doing something else in SomeClass_Observer_AnObserver::hook()
-
Check your local software firewall on your computer.
-
how to prevent my website from being saved by someone?
Daniel0 replied to angel777's topic in Miscellaneous
It's impossible. Just forget about as you'll just annoy your users. Everything has to be downloaded to the browser's cache anyways as it cannot parse things which aren't on the computer. -
No. You're using that function on the user input to ensure that arbitrary SQL cannot be injected into your query. It only works on strings, integers, floats and booleans. There is no point in running it on the results which are returned anyways.
-
Yeah. That'd be no problem. Although if it's a string value you'll have to enclose it in single quotes in the query.
-
When you're preparing a query you're not supposed to include the values. You'll rather put in placeholders which will then later be replaced with the data when you're executing the statement. I.e. $sth = $db->prepare('INSERT INTO test (name, surname) VALUES (?, ?)'); $res = $db->execute('John', 'Smith'); You might want to use PDO instead. It comes with PHP by default and since it's written in C it'll run faster than whatever PEAR library you're using.
-
To refer to something in the object scope you'll have to use the -> operator. Inside an object $this will always hold a reference to the object. It's the exact same concept as doing things like $user->username or something like that. To answer your question: yes. It won't be a problem. Variable variables only work inside strings when using complex syntax so the first dollar sign will be interpreted as a literal dollar sign where as the following one will be interpreted as a variable. See this example to demonstrate it: <?php $balance = '10'; echo "Balance is $$balance"; // Output: Balance is $10 ?>
-
Following on Andy's post. Reading the manual entry for sprintf() will answer that question.
-
What do you mean. You don't need PHP for that. Anyways, you can do this: <?php echo "<table>"; for ($i = 0; $i <= 10; $i++) { echo "<tr>"; for ($j = 0; $j <= 4; $j++) { echo "<td>test</td>"; } echo "</tr>"; } echo "</table>"; ?>
-
In the withdraw(), deposit() and display() methods you need to reference it as $this->balance (same goes for the other ones as well) like you did in the constructor.