underscore-php
underscore-php copied to clipboard
PHP Fatal error: Cannot use Underscore\Types\String as String because 'String' is a special class name
Can this be fixed in the 1.x branch please? Thanks!
Try:
use Underscore\Types\String as BaseString;
I don't really have any OS time lately but I'll try to make a new release with the fix on develop as soon as I can
This issue is very confusing, as I'm using the following code in my composer.json
:
{
"require": {
"radic/tmp-underscore-php": "dev-master"
}
}
which points to https://github.com/radic-forks/underscore-php as a source code at the packagist repository.
This problem doesn't exist in this repository in the current master
branch. So I've generated pull request against radic-forks/underscore-php
at radic-forks/underscore-php/pull/1 which is maintained by @RobinRadic.
I am having this problem as well. Says this only works on php 4.3.0
Solution
Here is the workaround which involves patching:
{
"require": {
"anahkiasen/underscore-php": "^1.3"
},
"require-dev": {
"cweagans/composer-patches": "~1.0"
},
"extra": {
"enable-patching": "true",
"patches": {
"anahkiasen/underscore-php": {
"Fixes PHP Fatal error: Cannot use Underscore\\Types\\String as String":
"https://github.com/kenorb-contrib/underscore-php/commit/10ef6b69b260d87647801fd19f2e2c9bb2a2f599.patch"
}
}
}
}
It should work well. Ideally replace the patch from your own fork or local file.
Patch file:
From 10ef6b69b260d87647801fd19f2e2c9bb2a2f599 Mon Sep 17 00:00:00 2001
From: kenorb <[email protected]>
Date: Tue, 14 Nov 2017 12:38:07 +0000
Subject: [PATCH] Fixes PHP Fatal error: Cannot use Underscore\Types\String as
String (ref: Anahkiasen/underscore-php/issues/96)
---
src/Methods/StringMethods.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Methods/StringMethods.php b/src/Methods/StringMethods.php
index 52c2ee6..f696135 100644
--- a/src/Methods/StringMethods.php
+++ b/src/Methods/StringMethods.php
@@ -2,7 +2,7 @@
namespace Underscore\Methods;
use Illuminate\Support\Str;
-use Underscore\Types\String;
+use Underscore\Types\String as BaseString;
/**
* Methods to manage strings
@@ -48,7 +48,7 @@ public static function accord($count, $many, $one, $zero = null)
*/
public static function randomStrings($words, $length = 10)
{
- return String::from('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
+ return BaseString::from('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
->shuffle()
->split($length)
->slice(0, $words)
Does @RobinRadic want to be added as collaborator to this repo maybe? If he's maintaining a stable fork it could be easier to let him update this repository directly
@Anahkiasen a similar patch is needed for Object as well, got the following error when using PHP Version 7.2:
PHP Fatal error: Cannot use 'Object' as class name as it is reserved.
Please see the similar issue on yii2's Repository