php-5.3

PHP `DateTime::days` returns trash?

倖福魔咒の 提交于 2019-12-19 17:14:24
问题 PHP Class DateInterval has a property "days". According to the manual it returns "Total number of days the interval spans. If this is unknown, days will be FALSE." In my case the code: $d = new DateInterval('P1Y'); echo $d->days; returns -99999 and a code like this $a = DateTime::createFromFormat("d.m.Y", "01.01.2010"); $b = DateTime::createFromFormat("d.m.Y", "03.01.2010"); $d = $b->diff($a); echo $d->days; returns 6015 Did I misunderstand something? 回答1: DateInterval is buggy on windows

ereg_replace for PHP 5.3 +?

怎甘沉沦 提交于 2019-12-19 10:45:30
问题 I've seen a solution for not having to rework usage of the ereg function for PHP 5.3: Good alternative to eregi() in PHP It uses if(!function_exists.... Is there a function that can be used in this way for ereg_replace ? ereg_replace("<!--.*-->","",$str); ereg_replace("[^a-z,A-Z]", "", $str); 回答1: Use the PCRE function preg_replace instead: preg_replace("/<!--.*-->/", "", $str); preg_replace("/[^a-z,A-Z]/", "", $str); POSIX ERE is (nearly) a complete subset of PCRE. So you can use (nearly)

php array_map callback parameter scope

☆樱花仙子☆ 提交于 2019-12-18 21:16:24
问题 In the following code the callback function passed to wrap_map can't see the argument in the outer function, why? (see code comment for detail) public static function wrap_implode($ar, $wrap, $delim){ echo "wrap is $wrap"; //wrap is ok $res = array_map(function($val){ echo "wrap is $wrap"; //wrap is not set here! return $wrap. $val . $wrap; }, $ar); return implode($delim, $res); } 回答1: Because it is in another scope. If you want to use $wrap , try: function($val) use ($wrap){ //etc } Of

Self Executing functions in PHP5.3?

不羁岁月 提交于 2019-12-18 11:10:30
问题 I was trying to borrow some programing paradigms from JS to PHP (just for fun). Is there a way of doing: $a = (function(){ return 'a'; })(); I was thinking that with the combination of use this can be a nice way to hide variables JS style $a = (function(){ $hidden = 'a'; return function($new) use (&$hidden){ $hidden = $new; return $hidden; }; })(); right now I need to do: $temp = function(){....}; $a = $temp(); It seems pointless... 回答1: Function Call Chaining, e.g. foo()() is in discussion

Multidimensional array to array

给你一囗甜甜゛ 提交于 2019-12-18 07:00:27
问题 I often have a 2-dimensional array: array( array('key' => 'value1'), array('key' => 'value2'), ... ); And need to form a 1-dimensional array: array('value1', 'value2') This can easily be done with foreach, but I wonder if there's some php 5.3 way to do it in one line. 回答1: $new_array = array_map(function($el) { return $el['key']; }, $array); 回答2: <?php $arr = array(array(141,151,161,140),2,3,array(101,202,array(303,404),407)); function array_oned($arrays){ static $temp_array = array();

Non-deterministic object reference bug in PHP 5.3.X

情到浓时终转凉″ 提交于 2019-12-18 05:05:15
问题 As of yesterday (perhaps after a recent PHP update?), I'm getting some very strange non-deterministic bugs in php 5.3.3. These appear in our production server in PHP 5.3.2 as well. The errors essentially amount to Fatal error: Uncaught exception 'ErrorException' with message 'Attempt to assign property of non-object' in various parts of the code base. Generally, the error line is something like: $this->foo = $bar in a __construct() call. $this is not found in the constructor?! I have no idea

PHP Reflection: How to know if a ReflectionMethod is inherited?

核能气质少年 提交于 2019-12-17 20:37:52
问题 In the ReflectionMethod documentation, I can't find anything to know wether a method was inherited from its parent class or defined in the reflected class. Edit: I use ReflectionClass::getMethods(). I want to know for each method if it has been defined in the class being reflected, or if it has been defined in a parent class. In the end, I want to keep only the methods defined in the current class. class Foo { function a() {} function b() {} } class Bar extends Foo { function a() {} function

How to connect to MSSQL 2000 from PHP 5.3 and up

两盒软妹~` 提交于 2019-12-17 19:02:55
问题 I have a legacy business application built on MS SQL Server 2000. I have some webbased utilities that access this database using PHP 5.2 with mssql extension. I need to reinstall the web server, and I looked forward to upgrade to PHP 5.4. Unfortunately, the mssql extension is not supported on PHP 5.3 and newer. There is the sqlsrv extension available form Microsoft, but the description says that it is only supported for accessing SQL server 2005 and up. How can I connect to my SQL Server 2000

How to connect to MSSQL 2000 from PHP 5.3 and up

会有一股神秘感。 提交于 2019-12-17 19:02:00
问题 I have a legacy business application built on MS SQL Server 2000. I have some webbased utilities that access this database using PHP 5.2 with mssql extension. I need to reinstall the web server, and I looked forward to upgrade to PHP 5.4. Unfortunately, the mssql extension is not supported on PHP 5.3 and newer. There is the sqlsrv extension available form Microsoft, but the description says that it is only supported for accessing SQL server 2005 and up. How can I connect to my SQL Server 2000

How to detect if a user uploaded a file larger than post_max_size?

☆樱花仙子☆ 提交于 2019-12-17 16:45:12
问题 How should I go about handling http uploads that exceeds the post_max_size in a sane manner? In my configuration post_max_size is a few MB larger than upload_max_filesize The problems I'm having are: If a user uploads a file exceeding post_max_size The _POST array is empty The _FILES array is empty, and of course any error codes therein are not present. No other info what kind of form post it is is accessible through theses means. Part of the problem is that the receiving script takes