Nueva pregunta

Pregunta:

Fecha: 23-08-2017 06:54:27 (En Español)

Fatal error: Cannot use PhpOffice\PhpWord\Shared\String as String because 'String' is a special class name[Resuelta]

Hola buenas tarde tengo un error al convertir los datos de una base de datos en un documento word,
mi programa se basa en notas y asistencias, y se puede descargar a través de un documento word pero al presionar descargar de tira el siguiente error:


Fatal error: Cannot use PhpOffice\PhpWord\Shared\String as String because 'String' is a special class name in W:\xampp\htdocs\web1\PhpWord\Element\Text.php on line 20

Este es el codigo

<?php

namespace PhpOffice\PhpWord\Element;

use PhpOffice\PhpWord\Shared\String;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;

class Text extends AbstractElement
{
   
    protected $fontStyle;

    protected $paragraphStyle;

    public function __construct($text = null, $fontStyle = null, $paragraphStyle = null)
    {
        $this->setText($text);
        $paragraphStyle = $this->setParagraphStyle($paragraphStyle);
        $this->setFontStyle($fontStyle, $paragraphStyle);
    }

    public function setFontStyle($style = null, $paragraphStyle = null)
    {
        if ($style instanceof Font) {
            $this->fontStyle = $style;
            $this->setParagraphStyle($paragraphStyle);
        } elseif (is_array($style)) {
            $this->fontStyle = new Font('text', $paragraphStyle);
            $this->fontStyle->setStyleByArray($style);
        } elseif (null === $style) {
            $this->fontStyle = new Font('text', $paragraphStyle);
        } else {
            $this->fontStyle = $style;
            $this->setParagraphStyle($paragraphStyle);
        }

        return $this->fontStyle;
    }

    public function getFontStyle()
    {
        return $this->fontStyle;
    }

    public function setParagraphStyle($style = null)
    {
        if (is_array($style)) {
            $this->paragraphStyle = new Paragraph;
            $this->paragraphStyle->setStyleByArray($style);
        } elseif ($style instanceof Paragraph) {
            $this->paragraphStyle = $style;
        } elseif (null === $style) {
            $this->paragraphStyle = new Paragraph;
        } else {
            $this->paragraphStyle = $style;
        }

        return $this->paragraphStyle;
    }

    public function getParagraphStyle()
    {
        return $this->paragraphStyle;
    }

    public function setText($text)
    {
        $this->text = String::toUTF8($text);

        return $this;
    }

    public function getText()
    {
        return $this->text;
    }
}


Cualquier ayuda lo agradecería mucho
Etiquetas: Base de Datos - Javascript - MySQL - MySQL Desarrollo - PHP - PHP Avanzado - PHP Fatal error - PHP MySQLi - PHP PDO - PHP7 - POO - Pregunta - Script PHP - Web - XAMPP Votos: 0 - Respuestas: 2 - Vistas: 9 Compartir en: Google Facebook Twitter LinkedIn Link
 

Respuestas:

  • Fecha: 23-08-2017 07:10:36 Manuel,
    Sring es una palabra reservada.
    Puedes solucionarlo con un alias así:

    use PhpOffice\PhpWord\Shared\String as POString;
    


    y luego donde lo utilices haz el cambio apropiado:

    public function setText($text)
        {
            $this->text = POString::toUTF8($text);
            return $this;
        }
    
      Votos: 1 - Link respuesta
     
  • Fecha: 25-08-2017 14:22:41 Mucha Gracias Amigo Agradecido Saludos.   Votos: 0 - Link respuesta
     
Para participar activamente de la comunidad primero debes autenticarte, ingresa al sistema.Iniciar Sesión
 
frjcbbae garagebible.com