php-5.3

anonymous function performance in PHP [closed]

点点圈 提交于 2019-12-01 15:13:42
I'm starting to use functional programming paradigms in php and was wondering what the performance impacts are. Some googling just seems to say that there are some. To be specific, I would like to know: Is there actually a performance impact or is it an urban legend? What is the performance impact (hopefully someone out that has done benchmarks)? What causes this impact (if one exists)? Is it fixed cost, or per execution? Any resources you guys have would be greatly appreciated :) Thanks in advance Jory Geerts I did some testing with array_map(), calling it with: The name of a function ( array

anonymous function performance in PHP [closed]

倾然丶 夕夏残阳落幕 提交于 2019-12-01 14:07:09
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I'm starting to use functional programming paradigms in php and was wondering what the performance impacts are. Some googling just seems to say that there are some. To be specific, I would like to know: Is there

ereg_replace for PHP 5.3 +?

…衆ロ難τιáo~ 提交于 2019-12-01 12:47:16
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); 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) any POSIX ERE regular expression with a PREG implementation. See the Regular Expression Flavor Comparison for

Peculiar Behaviour with PHP (5.3), static inheritance and references

只谈情不闲聊 提交于 2019-11-30 19:08:12
I'm writing a library in PHP 5.3, the bulk of which is a class with several static properties that is extended from by subclasses to allow zero-conf for child classes. Anyway, here's a sample to illustrate the peculiarity I have found: <?php class A { protected static $a; public static function out() { var_dump(static::$a); } public static function setup($v) { static::$a =& $v; } } class B extends A {} class C extends A {} A::setup('A'); A::out(); // 'A' B::out(); // null C::out(); // null B::setup('B'); A::out(); // 'A' B::out(); // 'B' C::out(); // null C::setup('C'); A::out(); // 'A' B::out

php array_map callback parameter scope

℡╲_俬逩灬. 提交于 2019-11-30 18:47:21
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); } Because it is in another scope. If you want to use $wrap , try: function($val) use ($wrap){ //etc } Of course, your function here doesn't need a callback: return $wrap.implode($wrap.$delim.$wrap,$ar).$wrap; 来源: https

Laravel 4 Form builder Custom Fields Macro

佐手、 提交于 2019-11-30 15:57:15
问题 Im trying to create a custom HTML 5 date field for using in a laravel 4 framework view. {{ Form::macro('datetime', function($field_name) { return ''; }); }} {{ Form::label('event_start', 'Event Date', array('class' => 'control-label')) }} {{ Form::datetime('event_start') }} The only problem is the value is not being populated, and i do not know how to do this. Im using this form to create and edit a model called Event. how can i populate the value of this field? 回答1: Here's what I did: in my

Laravel 4 Form builder Custom Fields Macro

落花浮王杯 提交于 2019-11-30 15:20:44
Im trying to create a custom HTML 5 date field for using in a laravel 4 framework view. {{ Form::macro('datetime', function($field_name) { return ''; }); }} {{ Form::label('event_start', 'Event Date', array('class' => 'control-label')) }} {{ Form::datetime('event_start') }} The only problem is the value is not being populated, and i do not know how to do this. Im using this form to create and edit a model called Event. how can i populate the value of this field? Here's what I did: in my view I added the following macro <?php Form::macro('datetime', function($value) { return '<input type=

Peculiar Behaviour with PHP (5.3), static inheritance and references

梦想与她 提交于 2019-11-30 02:43:19
问题 I'm writing a library in PHP 5.3, the bulk of which is a class with several static properties that is extended from by subclasses to allow zero-conf for child classes. Anyway, here's a sample to illustrate the peculiarity I have found: <?php class A { protected static $a; public static function out() { var_dump(static::$a); } public static function setup($v) { static::$a =& $v; } } class B extends A {} class C extends A {} A::setup('A'); A::out(); // 'A' B::out(); // null C::out(); // null B:

Warning: preg_match() [function.preg-match]: Unknown modifier '-' [duplicate]

你。 提交于 2019-11-29 16:54:55
This question already has an answer here: Warning: preg_replace(): Unknown modifier ']' 3 answers I change ereg to preg_match for update mycode to PHP5.3 . now i see this warning in my page. how to fix this ? warning : Warning: preg_match() [function.preg-match]: Unknown modifier '-' in C:\xampp\htdocs\share\configs\functions.php on line 2645 old Code : if (!ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $dateOfBirth, $regs)) New Code (PHP 5.3): if (!preg_match ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $dateOfBirth, $regs)) Thanks You need to add delimiters : if (!preg_match ("/([0-9]{4})-([0-9]

Multidimensional array to array

浪尽此生 提交于 2019-11-29 11:35:32
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. $new_array = array_map(function($el) { return $el['key']; }, $array); <?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(); foreach($arrays as $key){ if(is_array($key)){ array_oned($key); }else { $temp_array [] = $key; } } return $temp_array;