Skip to content
This repository has been archived by the owner on Jul 6, 2019. It is now read-only.

PHP Fatal error: Cannot use Underscore\Types\String as String because 'String' is a special class name #96

Open
tomzx opened this issue Oct 11, 2016 · 7 comments · May be fixed by radic-forks/underscore-php#1

Comments

@tomzx
Copy link

tomzx commented Oct 11, 2016

Can this be fixed in the 1.x branch please? Thanks!

@oyepez003
Copy link

Try:

use Underscore\Types\String as BaseString;

@Anahkiasen
Copy link
Owner

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

@kenorb
Copy link

kenorb commented Nov 14, 2017

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/pull/1 which is maintained by @RobinRadic.

@tony-garand
Copy link

I am having this problem as well. Says this only works on php 4.3.0

@kenorb
Copy link

kenorb commented Jan 17, 2018

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)

@Anahkiasen
Copy link
Owner

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

@guychouk
Copy link

guychouk commented Apr 10, 2018

@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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
6 participants