Skip to content

Commit 323f5fe

Browse files
author
Dennis Stücken
committed
new php 7 functions added, IntlChar stub added
1 parent 425a1a1 commit 323f5fe

File tree

6 files changed

+1746
-1
lines changed

6 files changed

+1746
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# php7ify
22

3-
php7ify is a project that brings new php7 classes and exceptions to php 5.x
3+
php7ify is a project that brings new php7 classes, functions and exceptions to php 5.x
44

55
[![Build Status](https://travis-ci.org/dstuecken/php7ify.svg)](https://travis-ci.org/dstuecken/php7ify)
66
[![License](https://poser.pugx.org/dstuecken/php7ify/license)](https://packagist.org/packages/dstuecken/php7ify)

composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
"src/",
3232
"src/Exceptions/"
3333
],
34+
"files": [
35+
"src/Functions/preg_replace_callback_array.php",
36+
"src/Functions/error_clear_last.php",
37+
"src/Functions/intdiv.php"
38+
],
3439
"psr-4": {
3540
"dstuecken\\Php7ify\\": "src/"
3641
}

src/Functions/error_clear_last.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
* Clear the most recent error
4+
*
5+
* @link http://php.net/manual/de/function.error-clear-last.php
6+
*
7+
* @package dstuecken\php7ify
8+
* @author Dennis Stücken <[email protected]>
9+
*
10+
* @since 7.0
11+
*/
12+
if (!function_exists('error_clear_last'))
13+
{
14+
function error_clear_last()
15+
{
16+
set_error_handler('var_dump', 0);
17+
@trigger_error('');
18+
restore_error_handler();
19+
}
20+
}

src/Functions/intdiv.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* Integer division
4+
*
5+
* @link http://php.net/manual/de/function.intdiv.php
6+
*
7+
* @package dstuecken\php7ify
8+
* @author Dennis Stücken <[email protected]>
9+
*
10+
* @since 7.0
11+
*/
12+
if (!function_exists('intdiv'))
13+
{
14+
function intdiv($dividend, $divisor)
15+
{
16+
$dividend = (int) $dividend;
17+
$divisor = (int) $divisor;
18+
19+
if (0 === $divisor)
20+
{
21+
throw new \DivisionByZeroError('Division by zero');
22+
}
23+
24+
if (-1 === $divisor && ~PHP_INT_MAX === $dividend)
25+
{
26+
throw new \ArithmeticError('Division of PHP_INT_MIN by -1 is not an integer');
27+
}
28+
29+
return ($dividend - ($dividend % $divisor)) / $divisor;
30+
}
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* Perform a regular expression search and replace using callbacks
4+
*
5+
* @link http://php.net/manual/de/function.preg-replace-callback-array.php
6+
*
7+
* @package dstuecken\php7ify
8+
* @author Dennis Stücken <[email protected]>
9+
*
10+
* @since 7.0
11+
*/
12+
if (!function_exists('preg_replace_callback_array'))
13+
{
14+
function preg_replace_callback_array(array $patterns, $subject, $limit = -1, &$count = 0)
15+
{
16+
$count = 0;
17+
$result = '' . $subject;
18+
if (0 === $limit)
19+
{
20+
return $result;
21+
}
22+
23+
foreach ($patterns as $pattern => $callback)
24+
{
25+
$result = preg_replace_callback($pattern, $callback, $result, $limit, $c);
26+
$count += $c;
27+
}
28+
29+
return $result;
30+
}
31+
}

0 commit comments

Comments
 (0)