Jump to content

Daniel0

Staff Alumni
  • Posts

    11,885
  • Joined

  • Last visited

Everything posted by Daniel0

  1. You should always be running APC (or at least some sort of opcode cache) in a production environment. It'll speed up things up considerably. It's also nice being able to cache things in memory instead of on the disk.
  2. Just echo something. That will per definition be an HTTP response when it's served via a web server.
  3. Yeah I'd agree it's better practice, but strictly speaking it's not required.
  4. Depending on the version of PHP. No. I assume you're talking about PHP 4's lack of visibility keywords, but in PHP 4 the constructor was not called __construct(). Actually, public is optional for methods because things by default are public.
  5. Yeah, but to be honest, I consider that a bug more than a feature. When $bar('something') is callable, then $foo->bar('something') should be as well (assuming both refer to anonymous functions).
  6. class Foo {} $foo = new Foo(); $foo->bar = function() { echo 'test'; }; I wouldn't recommend that kind of code though. Javascript uses prototype based object orientation while PHP uses class based object orientation.
  7. If you're running PHP as (Fast)CGI you won't need to restart, but if you're running as an Apache module you have to (but you probably can't on shared hosting). I would say that your best bet is to convince your host to install that extension, or get a VPS if you have special needs. Shared hosting is rarely very good if you need a custom setup.
  8. Possibly one of the files you are including, or one of the constructors for the objects you instantiate are changing it. That is the danger of storing data globally in a program. I would make a local copy by doing something like $cart = $_SESSION['cart'] and then use that instead.
  9. Does anyone know a good way of blocking ads in Chrome? I tried both AdSweep and AdBlock+, but both of them suck. Is there anything that works as well as AdBlock Plus for Firefox? I changed from Firefox to Chrome because Firefox was becoming too slow. Basically it would become really sluggish when it reached 400 MB memory usage (which was pretty often). The only thing I really miss is proper ad blocking.
  10. Something like this should do it: extension=php_xmlrpc.so (or .dll if it's a Windows box) This assumes that php_xmlrpc.so is in the directory specified by the extension_dir directive.
  11. You need to put extension=path where path is the path the path to the extension you wish to load. You can also just uncomment the line that probably already exists in your php.ini.
  12. Why it does that depends on how you've written your code. Maybe you don't clean up unused resources. That's simple to fix. Just do manual garbage collection. Maybe you wrote your script recursively and the call stack keeps growing. In that case, you could refactor it to be tail recursive. Maybe you're just trying to keep all the generated data in memory. In that case, write it to permanent storage more frequently.
  13. Try var_dump'ing it justbefore you call the method.
  14. Well, you can see it like this: $GetVar is substituted with CarMake, so you end up with $CarMake. It's essentially because a variable in PHP can have any name that can be represented using the string data type, so you can also do stupid shit like this: <?php $hello = 'test'; ${'this is a ' . $hello} = 'foo'; $bar = 'this is a test'; echo $$bar;
  15. Nevermind the performance, it makes your code almost entirely unreadable.
  16. Right, that means your query failed, so you'll have to fix it. You could try echoing the query and see if it's generated correctly. You would also want to fix the SQL injection using mysql_real_escape_string, but that's unrelated to the error.
  17. Your query failed for some reason. Use mysql_error to see what error message MySQL returned.
  18. When asking people for help when getting an error, it's often a good idea telling what the error is.
  19. A NULL value would be better to represent the tree root because it specifically means that no such thing exists. When using InnoDB's referential integrity features, you would also get into trouble representing "no parent" with a numeric value (unless there is an object with ID 0 called "The Universe").
  20. There is no need for recursion: $db = new PDO('mysql:host=localhost;dbname=test', 'root', 'foo'); $res = $db->query('SELECT s.sname, c.cname FROM state AS s LEFT JOIN city AS c ON s.sid = c.state_id ORDER BY s.sname, c.cname'); $prevStateName = null; foreach ($res->fetchAll() as $city) { if ($city['sname'] !== $prevStateName) { echo $city['sname'] . PHP_EOL; } if ($city['cname'] !== null) { echo ' - ' . $city['cname'] . PHP_EOL; } $prevStateName = $city['sname']; } Output: Aruba Australia India - Delhi - Karnataka Netherlands Russia - TamilNadu
  21. You can use curl.
  22. Right, but there is the important distinction that isset() works on undefined variables.
  23. It means that it has been defined somewhere. For instance, if the following is a complete script, the variable $foo is not set, but the variable $var is: <?php $bar = 'foo'; var_dump(isset($foo), isset($bar));
  24. The language construct isset() checks if a variable is set while a null comparison checks if some sort of value equals the special value "null". empty() checks if the value of something can be considered empty (the manual tells what values those would be).
×
×
  • 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.