What exactly are late static bindings in PHP? Answer You definitely need to read Late Static Bindings in the PHP manual. However, I’ll try to give you a quick summary. Basically, it boils down to the fact that the self keyword does not follow the same rules of inheritance. self always resolves to the cl…
Tag: php
$date + 1 year?
I’m trying to get a date that is one year from the date I specify. My code looks like this: It’s returning the wrong date. Any ideas why? Answer To add one year to todays date use the following: For the other examples you must initialize $StartingDate with a timestamp value for example: Try this o…
Can’t save php.ini
I have PHP for FastCGI installed on Windows 7 through the Web Platform Installer. I need to edit php.ini to enable logging, but I’m not able to overwrite the existing file, apparently because …
PHP preg_replace non-greedy trouble
I’ve been using the following site to test a PHP regex so I don’t have to constantly upload: http://www.spaweditor.com/scripts/regex/index.php I’m using the following regex: /(.*?).{3}/ on the …
Is there a way to redefine a type hint to a descendant class when extending an abstract class?
I will be using the following example to illustrate my question: class Attribute {} class SimpleAttribute extends Attribute {} abstract class AbstractFactory { abstract public function update(…
PHP output to command line
I start my script from command line and it outputs things as they happen but a week ago it stopped outputing and now outputs everything when script finishes. I have ob_start() but as I know this does not effect command line output. Answer You need to remove ob_start()… try this code on the command line,…
Get parent directory of running script
In PHP, what would be the cleanest way to get the parent directory of the current running script relative to the www root? Assume I have: $_SERVER[‘SCRIPT_NAME’] == ‘/relative/path/to/script/index….
Cannot use string offset as an array in php
I’m trying to simulate this error with a sample php code but haven’t been successful. Any help would be great. “Cannot use string offset as an array” Answer For PHP4 …this reproduced the error: For PHP5 …this reproduced the error: (From bugs.php.net actually) Edit, so why d…
Why is $(document).ready not firing for me?
In a php file i have used include to include the following js.php file and prior to that i have included the jquery file. $(document).ready(function(){ …
How to use XMLReader in PHP?
I have the following XML file, the file is rather large and i haven’t been able to get simplexml to open and read the file so i’m trying XMLReader with no success in php I’ve unfortunately not found a good tutorial on this for PHP and would love to see how I can get each element content to s…