Cannot redeclare CodeIgniter Helper Class

2019-08-20 05:01发布

  [Fri Jul 27 03:08:18.935217 2018] [:error] [pid 11] [client 172.18.0.1:54146] PHP Fatal error:  Cannot redeclare CreateUniqeSlugOfuser() (previously declared in /var/www/public_html/livesite/application/helpers/MY_url_helper.php:111) in /var/www/public_html/livesite/application/helpers/my_url_helper.php on line 111

Above is the error, I thought maybe this was a simple rename the file in my directory to MY_url_helper with the uppercase but this did not fix the error as some sites have said. As it stands I have no idea how to fix this but I do have some clues.

I'm not a code igniter expert, I took on this project from another developer, but it currently works on their server. It does not work on my server however. Seeing as the issue is probably with autoloading, what could be the thing I'm doing wrong? Could a different version in PHP be causing this issue?

enter image description here

Another hunch is maybe it's some cache I have to change? I'm not sure though... any ideas are appreciated.

enter image description here

I will say after changing the file name the error still thinks I'm using the lowercase version? I know it's reading the file cause I can throw phpinfo in the file and it seems to trigger hence the image I uploaded as a result of that.

Update:: Did echo CI_VERSION command to find this (2.2.0). Maybe this version is not compatible with PHP 7.0?

php56 is for sure the version on the other server... I will see if I can get a docker image of this somehow.

Well 5.6 still error.

enter image description here

Dockerfile

FROM php:5.6-apache
MAINTAINER Joe Astrahan <jastrahan@poolservice.software>

RUN apt-get update && apt-get upgrade -y && \
    apt-get install -y \
    bzip2 curl git less mysql-client sudo unzip zip \
    libbz2-dev libfontconfig1 libfontconfig1-dev \
    libfreetype6-dev libjpeg62-turbo-dev libpng-dev libzip-dev && \
    rm -rf /var/lib/apt/lists/*


RUN docker-php-ext-install bz2 && \
    docker-php-ext-configure gd \
        --with-freetype-dir=/usr/include/ \
        --with-jpeg-dir=/usr/include/ && \
    docker-php-ext-install gd && \
    docker-php-ext-install iconv && \
    docker-php-ext-install opcache && \
    docker-php-ext-install pdo_mysql && \
    docker-php-ext-install zip

RUN curl -sS https://getcomposer.org/installer \
    | php -- --install-dir=/usr/local/bin --filename=composer

# Set environment variables for Apache so we know its user and group names
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data

# Configure Apache SSL and Standard Virtualhosts
COPY config/apache_default.conf /etc/apache2/sites-available/000-default.conf
COPY config/apache_default-ssl.conf /etc/apache2/sites-available/default-ssl.conf
COPY config/run /usr/local/bin/run

# Configure SSL Directories & Create Temporary SSL Keys
RUN mkdir /etc/apache2/ssl
RUN openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt  -subj "/C=US/ST=Florida/L=Fort Lauderdale/O=Pool Service Software LLC/OU=IT Department/CN=dev.poolservice.software.local"

RUN chmod +x /usr/local/bin/run
RUN a2enmod rewrite

#Configure SSL On Apache2 & Headers Mod
RUN a2enmod ssl
RUN a2enmod headers
RUN service apache2 restart
RUN a2ensite default-ssl.conf
RUN service apache2 restart

#Install Zip & Unzip
RUN apt-get update \
    && DEBIAN_FRONTEND=noninteractive apt-get install zip unzip -y

#Install NodeJS
RUN apt-get update \
     && DEBIAN_FRONTEND=noninteractive apt-get install -y \
     software-properties-common

EXPOSE 80
EXPOSE 443

CMD ["/usr/local/bin/run"]

2条回答
女痞
2楼-- · 2019-08-20 05:38

So I solved the issue. Turns out PHP version didn't really make a difference, my docker file was changed to PHP 7.0 since it worked with that, I'll attach it below.

It turns out that CodeIgniter 2.x was using mysql instead of mysqli, so I changed all references in the code accordingly. Also I had to rename the file my_url_helper to just urlhelper_helper and then in the autoload file change it accordingly so it would load the correct file. For some reason even though it worked on the old server, I had to do this to get it to work with either version of PHP.

These fixes were all that were necessary to fix it.

查看更多
Animai°情兽
3楼-- · 2019-08-20 05:49

Maybe you already loaded the helper either in autoload or a class that was initialized before you attempted to load it again. CI is able to prevent duplicates with classes but not pure php helper files. That is why they surround their functions with:

if (!function_exists('functionname')) { ... }

I would suggest you do the same.

查看更多
登录 后发表回答