2

I want to export some data in an Excel file, I got This error.

A PHP Error was encountered Severity: Compile Error

Message: Cannot redeclare class Excel

Filename: libraries/EXcel.php

Line Number: 9

I try some way but no one works in my case. like 1 2

This is my EXcel.php codes

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

require_once APPPATH."third_party/PHPExcel/PHPExcel.php";
// var_dump(get_declared_classes());
class Excel extends PHPExcel {
    public function __construct() {
        parent::__construct();
    }
}
?>

what is wrong, thanks.

and this is my Var_dump result:

array (size=205)
  0 => string 'stdClass' (length=8)
  1 => string 'Exception' (length=9)
  2 => string 'ErrorException' (length=14)
  3 => string 'Closure' (length=7)
  4 => string 'Generator' (length=9)
  5 => string 'DateTime' (length=8)
  6 => string 'DateTimeImmutable' (length=17)
  7 => string 'DateTimeZone' (length=12)
  8 => string 'DateInterval' (length=12)
  9 => string 'DatePeriod' (length=10)
  10 => string 'LogicException' (length=14)
  11 => string 'BadFunctionCallException' (length=24)
  12 => string 'BadMethodCallException' (length=22)
  13 => string 'DomainException' (length=15)
  14 => string 'InvalidArgumentException' (length=24)
  15 => string 'LengthException' (length=15)
  16 => string 'OutOfRangeException' (length=19)
  17 => string 'RuntimeException' (length=16)
  18 => string 'OutOfBoundsException' (length=20)
  19 => string 'OverflowException' (length=17)
  20 => string 'RangeException' (length=14)
  21 => string 'UnderflowException' (length=18)
  22 => string 'UnexpectedValueException' (length=24)
  23 => string 'RecursiveIteratorIterator' (length=25)
  24 => string 'IteratorIterator' (length=16)
  25 => string 'FilterIterator' (length=14)
  26 => string 'RecursiveFilterIterator' (length=23)
  27 => string 'CallbackFilterIterator' (length=22)
  28 => string 'RecursiveCallbackFilterIterator' (length=31)
  29 => string 'ParentIterator' (length=14)
  30 => string 'LimitIterator' (length=13)
  31 => string 'CachingIterator' (length=15)
  32 => string 'RecursiveCachingIterator' (length=24)
  33 => string 'NoRewindIterator' (length=16)
  34 => string 'AppendIterator' (length=14)
  35 => string 'InfiniteIterator' (length=16)
  36 => string 'RegexIterator' (length=13)
  37 => string 'RecursiveRegexIterator' (length=22)
  38 => string 'EmptyIterator' (length=13)
  39 => string 'RecursiveTreeIterator' (length=21)
  40 => string 'ArrayObject' (length=11)
  41 => string 'ArrayIterator' (length=13)
  42 => string 'RecursiveArrayIterator' (length=22)
  43 => string 'SplFileInfo' (length=11)
  44 => string 'DirectoryIterator' (length=17)
  45 => string 'FilesystemIterator' (length=18)
  46 => string 'RecursiveDirectoryIterator' (length=26)
  47 => string 'GlobIterator' (length=12)
  48 => string 'SplFileObject' (length=13)
  49 => string 'SplTempFileObject' (length=17)
  50 => string 'SplDoublyLinkedList' (length=19)
  51 => string 'SplQueue' (length=8)
  52 => string 'SplStack' (length=8)
  53 => string 'SplHeap' (length=7)
  54 => string 'SplMinHeap' (length=10)
  55 => string 'SplMaxHeap' (length=10)
  56 => string 'SplPriorityQueue' (length=16)
  57 => string 'SplFixedArray' (length=13)
  58 => string 'SplObjectStorage' (length=16)
  59 => string 'MultipleIterator' (length=16)
  60 => string 'ReflectionException' (length=19)
  61 => string 'Reflection' (length=10)
  62 => string 'ReflectionFunctionAbstract' (length=26)
  63 => string 'ReflectionFunction' (length=18)
  64 => string 'ReflectionParameter' (length=19)
  65 => string 'ReflectionMethod' (length=16)
  66 => string 'ReflectionClass' (length=15)
  67 => string 'ReflectionObject' (length=16)
  68 => string 'ReflectionProperty' (length=18)
  69 => string 'ReflectionExtension' (length=19)
  70 => string 'ReflectionZendExtension' (length=23)
  71 => string 'SessionHandler' (length=14)
  72 => string '__PHP_Incomplete_Class' (length=22)
  73 => string 'php_user_filter' (length=15)
  74 => string 'Directory' (length=9)
  75 => string 'ZipArchive' (length=10)
  76 => string 'LibXMLError' (length=11)
  77 => string 'DOMException' (length=12)
  78 => string 'DOMStringList' (length=13)
  79 => string 'DOMNameList' (length=11)
  80 => string 'DOMImplementationList' (length=21)
  81 => string 'DOMImplementationSource' (length=23)
  82 => string 'DOMImplementation' (length=17)
  83 => string 'DOMNode' (length=7)
  84 => string 'DOMNameSpaceNode' (length=16)
  85 => string 'DOMDocumentFragment' (length=19)
  86 => string 'DOMDocument' (length=11)
  87 => string 'DOMNodeList' (length=11)
  88 => string 'DOMNamedNodeMap' (length=15)
  89 => string 'DOMCharacterData' (length=16)
  90 => string 'DOMAttr' (length=7)
  91 => string 'DOMElement' (length=10)
  92 => string 'DOMText' (length=7)
  93 => string 'DOMComment' (length=10)
  94 => string 'DOMTypeinfo' (length=11)
  95 => string 'DOMUserDataHandler' (length=18)
  96 => string 'DOMDomError' (length=11)
  97 => string 'DOMErrorHandler' (length=15)
  98 => string 'DOMLocator' (length=10)
  99 => string 'DOMConfiguration' (length=16)
  100 => string 'DOMCdataSection' (length=15)
  101 => string 'DOMDocumentType' (length=15)
  102 => string 'DOMNotation' (length=11)
  103 => string 'DOMEntity' (length=9)
  104 => string 'DOMEntityReference' (length=18)
  105 => string 'DOMProcessingInstruction' (length=24)
  106 => string 'DOMStringExtend' (length=15)
  107 => string 'DOMXPath' (length=8)
  108 => string 'PDOException' (length=12)
  109 => string 'PDO' (length=3)
  110 => string 'PDOStatement' (length=12)
  111 => string 'PDORow' (length=6)
  112 => string 'SimpleXMLElement' (length=16)
  113 => string 'SimpleXMLIterator' (length=17)
  114 => string 'XMLReader' (length=9)
  115 => string 'XMLWriter' (length=9)
  116 => string 'CURLFile' (length=8)
  117 => string 'COMPersistHelper' (length=16)
  118 => string 'com_exception' (length=13)
  119 => string 'com_safearray_proxy' (length=19)
  120 => string 'variant' (length=7)
  121 => string 'com' (length=3)
  122 => string 'dotnet' (length=6)
  123 => string 'finfo' (length=5)
  124 => string 'GMP' (length=3)
  125 => string 'Collator' (length=8)
  126 => string 'NumberFormatter' (length=15)
  127 => string 'Normalizer' (length=10)
  more elements...
Community
  • 1
  • 1
Nasser Ali Karimi
  • 4,462
  • 6
  • 34
  • 77
  • You should look into autoloading instead of manually including the classes you need. Check http://php.net/manual/en/language.oop5.autoload.php or use for example Composer's autoloader. – jeroen Jan 11 '19 at 08:00

2 Answers2

2

The Excel class is already declared in your project.

Please change your file name and class name of controller to something different. I hope this will solve your problem.

Krzysztof Raciniewski
  • 4,735
  • 3
  • 21
  • 42
Sandeep K.
  • 759
  • 6
  • 18
1

source: Bryan Hazelbaker

Depending on your OS, and how you have constructed the path to your document root, there may be an issue with capitals versus lower case letters in the path name.

  1. rename the file from EXcel.php to excel.php (i.e. use lower case)
  2. ensure to always use require_once (i.e. require_once /path/to/excel.php)
  3. at last you could test above with print_r(get_declared_classes()); (which could show you that the first include is from autoload)
Community
  • 1
  • 1
Top-Master
  • 7,611
  • 5
  • 39
  • 71