php-5.2

Namespaces in php 5.2

喜欢而已 提交于 2019-11-28 07:31:26
问题 I've done little web using namespaces. I have it in my computer and i'm about to moving it to free hosting that uses php 5.2. Syntax highlighter for php 5.2 interprets them as errors. Are namespaces supported by php 5.2? If not is there any way how to use them with little changes to existing code? 回答1: Namespaces are not supported prior to 5.3. There isn't really a way to adapt for them into 5.2 unfortunately. 回答2: Namespaces are only available as of 5.3 At least in the case of classes, you

php dateTime::createFromFormat in 5.2?

喜欢而已 提交于 2019-11-27 23:51:36
I have been developing on php 5.3. However our production server is 5.2.6. I have been using $schedule = '31/03/2011 01:22 pm'; // example input if (empty($schedule)) $schedule = date('Y-m-d H:i:s'); else { $schedule = dateTime::createFromFormat('d/m/Y h:i a', $schedule); $schedule = $schedule->format('Y-m-d H:i:s'); } echo $schedule; However that function is not available in 5.2 What is the easiest way to get around this (no chance of a php upgrade). just include the next code function DEFINE_date_create_from_format() { function date_create_from_format( $dformat, $dvalue ) { $schedule =

PHP get_called_class() alternative

倖福魔咒の 提交于 2019-11-27 17:37:40
问题 I've got an Abstract PHP superclass, which contains code that needs to know which subclass its running under. class Foo { static function _get_class_name() { return get_called_class(); //works in PHP 5.3.*, but not in PHP 5.2.* } static function other_code() { //needs to know echo self::_get_class_name(); } } class Bar extends Foo { } class FooBar extends Foo { } Bar::other_code(); // i need 'Bar' FooBar::other_code(); // i need 'FooBar' This would work if I called the function get_called

How to Run PHP on IIS7.5 Express?

爱⌒轻易说出口 提交于 2019-11-27 17:30:43
问题 I have Win XP SP3 and have installed IIS7.5 Express and want to run PHP on it. I am able to run simple HTML code on the server, I am able to start and stop the server by running iisservices.exe, but I am not able to run php scripts on it. If I have the following PHP file: <? php echo "hello world"; ?> <html>HI</html> The output is HI but the PHP script doesn't run. I have followed the steps described in this article to install PHP: http://learn.iis.net/page.aspx/724/install-and-configure-php/

PHP HTTP-Request

微笑、不失礼 提交于 2019-11-27 15:43:35
I have MAMP Pro installed running php 5.2.13. When I try to initialize a HTTP-Request $r = new HttpRequest('http://example.com/', HttpRequest::METH_GET); it tells me: "Class 'HttpRequest' not found in ...". What do I need to do to 'install(?)' it? You must enable http extension: http://www.php.net/manual/en/http.setup.php Or you can try new HTTP_Request2: sudo pear install --alldeps HTTP_Request2-alpha And then: $req = new HTTP_Request2('your.url'); $req->setMethod('POST'); $req->setHeader("content-type", $mimeType); $req->setBody(''); $response = $req->send(); Contemporary Answer for MAMP 2.0

PHP Shorthand ternary operator “?:” Parse error unexpected “:”

柔情痞子 提交于 2019-11-27 15:33:16
问题 I've just uploaded some old PHP files to a new server and am getting parse errors (Unexpected ':') on shorthand ternary ops. eg: $y = $x ?: "Some default"; php version is 5.2.16 The code is littered with these shorthand ?:, so before changing them all I thought I'd see if anyone knows anything about this as I've not used PHP for a while now. 回答1: This is only available since PHP 5.3 The expression (expr1) ? (expr2) : (expr3) evaluates to expr2 if expr1 evaluates to TRUE , and expr3 if expr1

php dateTime::createFromFormat in 5.2?

一个人想着一个人 提交于 2019-11-27 04:41:58
问题 I have been developing on php 5.3. However our production server is 5.2.6. I have been using $schedule = '31/03/2011 01:22 pm'; // example input if (empty($schedule)) $schedule = date('Y-m-d H:i:s'); else { $schedule = dateTime::createFromFormat('d/m/Y h:i a', $schedule); $schedule = $schedule->format('Y-m-d H:i:s'); } echo $schedule; However that function is not available in 5.2 What is the easiest way to get around this (no chance of a php upgrade). 回答1: just include the next code function

Parse error: syntax error, unexpected '[', expecting ')' [duplicate]

孤人 提交于 2019-11-27 02:05:54
This question already has an answer here: PHP syntax for dereferencing function result 22 answers I have this linecode $media = $dc->thumbnail->attributes()['url']; runs fine on my local (WAMP) php 5.4.3 but when i host it on my server cpanel then it gives this error Parse error: syntax error, unexpected '[', expecting ')' the php version on my server is 5.2.17 i dnt see any problem with it, please help You need to be running PHP 5.4+ to use shorthand arrays You can't have a php 5.4.3 and a 5.2.17 with a single WAMP installation, but from your error message, i think you are using the older one

What can use for DateTime::diff() for PHP 5.2?

只谈情不闲聊 提交于 2019-11-26 18:55:15
Is there any function equivalent to DateTime::diff() in PHP 5.2? My local server is PHP 5.3 and using DateTime::diff(). then I found that my live site uses PHP 5.2 and gives an error. Fatal error: Call to undefined method DateTime::diff() in /var/www/some/other/dir/web/daikon/modules/projects/views/admin/log/admin_log_list.php on line 40 The PHP code: foreach ($logs as $key => $list){ ... // show date in European way dd-mm-yyyy not in MySQL way yyyy-mm-dd $newdate =new DateTime($list['date']) ; echo "<td class=\"left\" width=\"8%\">".$newdate->format('d-m-Y')."</td>\n"; $starttime = new

mysqli_stmt_get_result alternative for php 5.2.6

a 夏天 提交于 2019-11-26 18:34:04
问题 I am not an expert of php, I developed a small service which query a mysql db. However I developed with php 5.4, and then discovered that my web hosting plan has 5.2.6, so I am having few problems with some undefined function. Specifically, in this case, how can I solve the mysqli_stmt_get_result undefined function available on > 5.3 ? Here is the code: $stmt = mysqli_prepare($con,$db_query); if($stmt) { mysqli_stmt_bind_param($stmt,'ss',$after,$lang); mysqli_stmt_execute($stmt); $result =