Jump to content

Alex

Staff Alumni
  • Posts

    2,467
  • Joined

  • Last visited

Everything posted by Alex

  1. Alex

    PHP 5 OOP

    OOP has nothing to do with security. If you don't know the advantages of OOP you shouldn't be using it. It's not an easy concept so don't beat yourself up if you don't understand it right away. In your limited example there would be no benefit in using OOP. If you haven't already you can check this link out to get some general information about OOP.
  2. You have the basic idea down. You would just need to store the average time taken in some way.
  3. I think there are times when static variables/methods do come in handy. You just need to know when to use them. I think it also depends on the specific coding practices for the particular language you're working with as well. For example in a language like ActionScript 3.0 that is almost explicitly Object Oriented it's standard practice to create a class specifically for defining constants. Ex: package { public class Constants { public static const SOME_CONSTANT:uint = 0; ... } } One practical example in PHP for why you would want to use a static property is such: Say you have a User class that has a property id. You want each User object's property id be an incrementing value starting at 0. You could achieve that like so: class User { private static $_nextID = 0; private $_id; public function __construct() { $this->_id = self::$_nextID++; } }
  4. You're forgetting "; on this line: echo "<tr><td><center><a href='index.php?pg=news&np=" . $row['id'] . "'>" . $row['title'] . "</a></center></td></tr> Should be: echo "<tr><td><center><a href='index.php?pg=news&np=" . $row['id'] . "'>" . $row['title'] . "</a></center></td></tr>";
  5. You would need to pass a reference of $a. This way instead of actually passing the value of $a you're passing the location in memory of $a. function foo(&$a) { $a = "changed by variable function"; } function bar($var_function) { $a = "original value"; $var_function($a); echo($a); } echo bar('foo');
  6. As of PHP 6.0.0 magic_quotes is removed.
  7. It would be the same of course. md5 wouldn't be of very much use if the hashes changed.
  8. You're missing a closing ): $sql = "INSERT INTO `smsinfo`.`history` ( `time` , `number` , `sms` , `price` , `smssent` ) VALUES (NOW(),$nr,$sms,$tariff,1)";
  9. $_SESSION, as session_register is depreciated as of PHP 5.3.0 and removed as of PHP 6.0.0.
  10. Comment out the Content-type header change and see what error it's giving you.
  11. Typically beginning a variable name with an underscore is used to denote private properties.
  12. Check if the url exists? You mean the directory? file_exists, if you read documentation, checks files and directories.
  13. Variable names cannot begin with numbers.
  14. Alex

    PHP GTK2

    I've never used PHP GTK2, or PHP GTK1 for that matter, so I decided to mess around it with. Using the documentation it seems pretty straightforward, but I have hit a snag. I'm using the GtkNotebook object and for one of its pages I've added a GtkVBox object. Like so: $this->main_list = new GtkVBox(); $this->book->append_page( $this->main_list, new GtkLabel('Main List') ); I then create a timer to run a function every 15 seconds (for example) and then call the function once at start-up as well. Gtk::timeout_add(1000 * 15, array($this, 'update')); $this->update(); The setup of the update method is basically like this: public function update() { // Attemping to remove all children from $this->main_list, if there are any foreach($this->main_list->get_children() as $child) { $this->main_list->remove($child); } foreach(...) // Some complex loops { // Construct a new GtkTable object ($table) // Add $table to $this->main_list $this->main_list->pack_start($table, false, false, 10); } return true; // otherwise the timer dies } Now, the first call to $this->update() works as expected and populates $this->main_list (on the GtkNotebook page) with the expected. However when it's called a second time by the timer instead of clearing all the children from the GtkNotebook page and populating it with the new newly constructed GtkTable objects the page is just cleared and nothing new is displayed. I've done all the debugging to make sure loops were producing the expected outputs and whatnot, so I figure it must be something simple I'm missing. Any ideas?
  15. It's possible the array was never explicitly defined. Doing something like this: <?php $foo['bar'] = 'foobar'; Is completely valid. Though, it's usually a good idea to define your arrays somewhere as not to create confusion if someone else is looking over your code.
  16. [ot]The tag is [ot] not [offtopic][/ot]
  17. The error is pretty self-explanatory, the arrays aren't the same lengths like your gave in your example. So clearly it won't work, you need to have the same amount of keys as elements, right?
  18. Or.. $newarr = array_combine(array_values($arr1), array_values($arr2));
  19. Just change your query to order in reverse: $newsquery=mysql_query("SELECT * FROM news ORDER BY timestamp ASC LIMIT 10");
  20. Single quotes don't have variable interpolation. Try: if(!preg_match("/{$this->ValidationExpression}/", $this->Value)) {
  21. Oh sorry. Your problem is that you're never closing the bracket opened here: if ($crank <= 4) {
×
×
  • 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.