New question

Question:

Date: 23-08-2017 06:54:27 (In Spanish)

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

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
Tags: Database - Javascript - MySQL - MySQL Developing - OOP - PHP - PHP Advanced - PHP Fatal error - PHP MySQLi - PHP PDO - PHP7 - Question - Script PHP - Web - XAMPP Votes: 0 - Answers: 2 - Views: 9 Share on: Google Facebook Twitter LinkedIn Link
 

Answers:

  • Date: 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;
        }
    
      Votes: 1 - Link answer
     
  • Date: 25-08-2017 14:22:41 Mucha Gracias Amigo Agradecido Saludos.   Votes: 0 - Link answer
     
To actively participate in the community first must authenticate, enter the system.Sign In
 
frjcbbae garagebible.com