php-5.2

php callback function in class

假装没事ソ 提交于 2019-12-09 15:08:35
问题 for some reasons, our hosting company used PHP 5.2 and doesn't even have mysqli and PDO pre-installed. I have no choice but to rewrite some part of my code to make it 5.2 compatible. so, here is my question: In PHP 5.2 Anonymous function is not supported, so i did the following test to make sure I'm changing the code correctly: class foo{ public function toString(){ $arr = array("a", "b"); $arr2 = array("c", "d"); print_r(array_map('mapKeyValue', $arr, $arr2)); } private function mapKeyValue(

$_SERVER['DOCUMENT_ROOT']

六月ゝ 毕业季﹏ 提交于 2019-12-08 10:56:30
问题 First of all, if you read this, thank you in advance for your patience,- I'm fairly new at PHP and have an issue which I will try to explain/describe. //set default path ///var/www/vhosts/www.mydomain.com/httpdocs/ $url = 'http://mydomain.com/skins/coolblue/tmp'; $url2 = 'http://mydomain.com/skins/coolblue/tmp'; $doc = $_SERVER['DOCUMENT_ROOT']; $path = '/templates/'; $actual_url = $doc.'/skins/coolblue/tmp'.$path; (I had a developer originally build my site and configure my server, but he's

PHP DateTime class just like v5.3 for PHP 5.2

做~自己de王妃 提交于 2019-12-08 05:11:04
问题 I've found a few problems in applications I've been doing where methods like DateTime::diff would be of much assistance, but my host with PHP 5.2 does not support DateTime::diff or any other from 5.3. Can anyone point to a class implementation similar to PHP's DateTime class from v5.3, but working for PHP 5.2? Thanks in advance 回答1: I use following wrapper class in my php5.2 apps: http://pastebin.ca/2051944. Untill php5.3 was released - it saves much my time 来源: https://stackoverflow.com

Preventing DOMDocument::loadHTML() from converting entities

让人想犯罪 __ 提交于 2019-12-07 11:45:12
问题 I have a string value that I'm trying to extract list items for. I'd like to extract the text and any subnodes, however, DOMDocument is converting the entities to the character, instead of leaving in the original state. I've tried setting DOMDocument::resolveExternals and DOMDocument::substituteEntities for false, but this has no effect. It should be noted I'm running on Win7 with PHP 5.2.17. Example code is: $example = '<ul><li>text</li>'. '<li>½ of this is <strong>strong</strong></li></ul>'

How to downgrade PHP version from 5.3 to 5.2 in Ubuntu 12.04?

萝らか妹 提交于 2019-12-07 06:40:30
问题 I have freshly installed Ubuntu 12.04 and I have installed PHP as well. By default, it is installed with version 5.3.10 but my PHP project doesn't support PHP v5.3.10. I want to downgrade PHP version to 5.2. How can I do it? 回答1: You would have to uninstall PHP and then reinstall an older version. However if your working on a project that your going to sell, or give to clients, or whatever the case my suggestion would be take out any functionality thats actually breaking between 5.2x and 5.3x

If condition for PHP Version ignore new code

旧时模样 提交于 2019-12-06 03:48:22
So I've got a script that needs to run on several sites. I've got one version of the script that is optimised with some new PHP 5.3 functions, however some sites are 5.2 etc. This code: if (version_compare(PHP_VERSION, '5.3.0') >= 0) { Do the optimised 5.3 code (Although 5.2 throws syntax errors for it) } else { do the slower version of code } However, on the 5.2 servers, it will detect the "syntax errors" in the first if condition, even though it technically should skip that content, I'm aware that PHP still scans the whole file. How can I get 5.2 to ignore the first if completely (I know I

Closure objects within arrays before PHP 5.3

冷暖自知 提交于 2019-12-05 15:16:57
I know it's possible to do the following with PHP 5.3 (anonymous functions), but is there a similar alternative in older PHP version (pre-5.3)? $exampleArray = array( 'func' => function() { echo 'this is an example'; } Is it possible to do this with __call or typecasting the function as an (object) first? Also, I tried making the function un-anonymous by giving it a name, but this didn't seem to work. If you want to create anonymous in PHP < 5.3, you can use create_function function. Also Here is interesting information about callbacks (may be usefull). Example using create_function # This

Preventing DOMDocument::loadHTML() from converting entities

て烟熏妆下的殇ゞ 提交于 2019-12-05 11:49:24
I have a string value that I'm trying to extract list items for. I'd like to extract the text and any subnodes, however, DOMDocument is converting the entities to the character, instead of leaving in the original state. I've tried setting DOMDocument::resolveExternals and DOMDocument::substituteEntities for false, but this has no effect. It should be noted I'm running on Win7 with PHP 5.2.17. Example code is: $example = '<ul><li>text</li>'. '<li>½ of this is <strong>strong</strong></li></ul>'; echo 'To be converted:'.PHP_EOL.$example.PHP_EOL; $doc = new DOMDocument(); $doc->resolveExternals =

PHP Object Life Time

为君一笑 提交于 2019-12-04 09:19:28
I am using PHP 5.2. If I new an object at one page, when will this object be destructed? Is the object destructed automatic at the time that user go to another .php page or I need to call __destructor explicitly? It will be destructed (unloaded from memory) at the end of the page load, or if you unset all references to it earlier. You will not have to destroy it manually since PHP always cleans up all memory at the end of the script. In fact, you should never call __destruct yourself. Use unset to unset the reference to an object when you want to destroy it. __destruct will in fact not destroy

php callback function in class

主宰稳场 提交于 2019-12-04 01:23:04
for some reasons, our hosting company used PHP 5.2 and doesn't even have mysqli and PDO pre-installed. I have no choice but to rewrite some part of my code to make it 5.2 compatible. so, here is my question: In PHP 5.2 Anonymous function is not supported, so i did the following test to make sure I'm changing the code correctly: class foo{ public function toString(){ $arr = array("a", "b"); $arr2 = array("c", "d"); print_r(array_map('mapKeyValue', $arr, $arr2)); } private function mapKeyValue($v, $k){ return $k."='".$v."'"; } } $foo = new foo(); echo $foo->toString(); but the above would give