Php windows call to undefined

PHP Call to undefined function

I am trying to call a function from another function. I get an error:

controller.php file:

model/model.php

Things already tried:

  1. Verified that the require_once works, and the file exists in the specified location.
  2. Verified that the function exists in the file.

I am not able to figure this out. Am I missing something here?

7 Answers 7

How to reproduce the error, and how to fix it:

Put this code in a file called p.php :

Run it like this:

Solution: use $this->salt(); instead of salt();

So do it like this instead:

If someone could post a link to why $this has to be used before PHP functions within classes, yeah, that would be great.

This was a developer mistake — a misplaced ending brace, which made the above function a nested function.

I see a lot of questions related to the undefined function error in SO. Let me note down this as an answer, in case someone else have the same issue with function scope.

Things I tried to troubleshoot first:

  1. Searched for the php file with the function definition in it. Verified that the file exists.
  2. Verified that the require (or include) statement for the above file exists in the page. Also, verified the absolute path in the require/include is correct.
  3. Verified that the filename is spelled correctly in the require statement.
  4. Echoed a word in the included file, to see if it has been properly included.
  5. Defined a separate function at the end of file, and called it. It worked too.

It was difficult to trace the braces, since the functions were very long — problem with legacy systems. Further steps to troubleshoot were this:

    I already defined a simple print function at the end of included file. I moved it to just above the «undefined function». That made it undefined too.

Identified this as some scope issue.

Used the Netbeans collapse (code fold) feature to check the function just above this one. So, the 1000 lines function above just collapsed along with this one, making this a nested function.

Once the problem identified, cut-pasted the function to the end of file, which solved the issue.

Call to undefined function oci_connect()

I got this error.

that is the code.

This is the error I got.

I checked the PHP DLL files in ext folder.

Somebody help on this issue thanks in advance.

12 Answers 12

I just spend THREE WHOLE DAYS fighting against this issue.

I was using my ORACLE connection in Windows 7, and no problem. Last week I Just get a new computer with Windows 8. Install XAMPP 1.8.2. Every app PHP/MySQL on this server works fine. The problem came when I try to connect my php apps to Oracle DB.

Call to undefined function oci_pconnect()

And when I start/stop Apache with changes, a strange «Warning» on «PHP Startup» that goes to LOG with «PHP Warning: PHP Startup: in Unknown on line 0»

I did everything (uncommented php_oci8.dll and php_oci8_11g.dll, copy oci.dll to /ext directory, near /Apache and NOTHING it works. Download every version of Instant Client and NOTHING.

Читайте также:  Активация микрофона по кнопке windows

God came into my help. When I download ORACLE Instant Client 32 bits, everything works fine. phpinfo() displays oci8 info, and my app works fine.

So, NEVER MIND THAT YOUR WINDOWS VERSION BE x64. The link are between XAMPP and ORACLE Instant Client.

Simple steps

You need to enable the below extension in your php.ini

by removing the «;» so that the results will below:

Download Oracle Instant Client:- Preferably 32 bit. 32 bit will also work on 64 bit. You can just google: download oracle instant client windows 32 bit. Use version 11 of the client because extension=php_oci8_11.g.dll won’t work with 12. Unzip the package into a location such as C:\Oracle\instantclient_11_2 .

Finally modify the System’s PATH Environment Variable with end location, under system variables not user variables

Then you need to restart the System for PATH changes to fully propagate.

If you just restart XAMPP/WAMP without restarting the machine the Client’s DLL files (i.e. OCL.dll) will not be loaded (nor found) by PHP’s php_oci8_11g.dll extension.

Things to Make sure

    Whenever you connecting Oracle Database , try to use 32 Bit oracle client libraries, Since XAMP PHP is compiled with 32 Bit(Though you have 64 Bit windows Machine)

Download Oracle Client from Download From here

Paste it in C:\instantclient_12_1

  • Then Set the path to above in System Environment Variable
  • Then Go to C:\xampp\php\php.ini and uncomment extension=php_oci8_12c.dll
  • Then Restart the XAMP and it should work without any Issue.
  • You need to enable that extension in your php.ini file. See Oracle Installation:

    I installed WAMPServer 2.5 (32-bit) and also encountered an oci_connect error. I also had Oracle 11g client (32-bit) installed. The common fix I read in other posts was to alter the php.ini file in your C:\wamp\bin\php\php5.5.12 directory, however this never worked for me. Maybe I misunderstood, but I found that if you alter the php.ini file in the C:\wamp\bin\apache\apache2.4.9 directory instead, you will get the results you want. The only thing I altered in the apache php.ini file was remove the semicolon to extension=php_oci8_11g.dll in order to enable it. I then restarted all the services and it now works! I hope this works for you.

    First, use

    and determine your PHP Version (located at the very top, e.g. 7.0.xxx) and also, your PHP Version architecture: x64 or x86 and also, Thread Safe or Not THread Safe (located in the first table as «Thread Safety».) «Disabled» obviously means «Not Thread Safe».

    It is absolutely critical that the following three pieces of software that you will need are:

    1. for the same major version of PHP (7.0 for 7.0.xxx)
    2. same version of Oracle as the version you are accessing (11g, 12g, etc)
    3. the same Not Thread Safe / Thread Safe version of PHP
    4. all for the same architecture.

    If any of the following are for a different architecture, Not Thread Safe/Thread Safe version, PHP major version number, or database version, you’ll get errors:

    Remember: If you are connecting to an 11g Oracle instance, you need an 11g driver.

    Second, install the correct PHP, OCI8 PECL Driver, and instant client.

    Third, modify d:\php\php.ini according the instructions given by Oracle:

    Fourth: Add d:\oci\ (or whatever your instant client install location is) to your system PATH.

    Читайте также:  Браузер nokia windows phone

    Fifth: reboot your PC.

    Sixth, on a command prompt, type «where oci*» and verify that your Instant Client install path version of oci.dll is present.

    Seventh, go to d:\php\ and type «php -m» and you should see OCI8 in the list.

    If you do not see OCI8 in the list of modules after typing «php -m», open up d:\php\errorlog.txt

    If you see something like:

    then either instant client or your PECL driver download is not the same architecture as your PHP version.

    If you see something like:

    then you are using the wrong OCI8 PECL driver for your version of instant client.

    Call to undefined function oci_connect, php_oci8_12c.dll, windows 8.1, php5.6.6

    I have a simple php script:

    When I run it (from a browser or from the command line), I get the error:

    I’m using php 5.6.6 which came with php_oci8_12c.dll already there.

    I have extension=php_oci8_12c.dll in my php.ini

    I have installed instant client (12.1) — tried 32 bit version AND 64 bit version

    I have ORACLE_HOME and TNS_ADMIN environment variables pointing at the instant client folder ( C:\instantclient_12_1 ).

    I also have C:\instantclient_12_1 in my path

    I have a tnsnames.ora in that same folder with this relevant entry in it:

    SQLDeveloper works, recognizes the above mentioned tnsnames.ora and connects and successfully runs a query on the same database that my php script is trying to access.

    I have spent several hours over several days trying different things to no avail.

    Some other information that might prove useful:

    I would ideally like to use oci 1.4.10 to match the production server, but not too worried about that for now.

    gives me this error:

    I can’t find any explanation on that error that means anything to me.

    What am I missing — can anyone help me

    I have tried the various suggestions in other posts on stackoverflow, namely:

    extension=oci8.so with and without extension=php_oci8_12c.dll

    I don’t have the line extension=php_oracle.dll in my php.ini file

    phpinfo tells me that I am using the correct php.ini file:

    This line from phpinfo might also be of use:

    It seems that dsp files are VC++ project files — I am now venturing on learning how to create a php extension, and hopefully when I’ve done that I’ll have enough knowledge to compile the oci8 1.4.10 source code into a dll that works on windows 8 — unless somebody rescues me with the answer to this question — this looks like it is going to take me some time 🙂

    Adding display_startup_errors = On to php.ini tells me that the oci dll is not a valid Win32 application

    2 Answers 2

    Edit: Hmm. Trying this on Windows 8 appears to generate the same error as you specified. I’m currently investigating.

    My mistake (I had enabled the wrong extension_dir line). It works in Win8 just as documented below.

    The following steps should be all you need to get OCI working with PHP (I’ve just verified this on a freshly installed Windows 2008 R2 Standard x64 virtual machine):

    • Download and extract PHP (I used C:\php from php-5.6.7-nts-Win32-VC11-x86.zip ).
    • Download and extract InstantClient (I used C:\instantclient_12_1 from instantclient-basic-nt-12.1.0.2.0.zip ).
    • Add the above paths to the system path.
    • Copy c:\php\php.ini-production to c:\php\php.ini .
    • in php.ini :
      • enabled line extension_dir = «ext» .
      • enabled line extension=php_oci8_12c.dll .
    • Install Microsoft Visual C++ 2010 Runtime (x86). This is needed for the OCI8 extension.
    • Install Microsoft Visual C++ 2012 Runtime (x86). This is needed for PHP.
    Читайте также:  Что такое виртуальная машина для windows 10 x64

    At this point running php —ri oci8 in a command prompt shows me the following output:

    And checking for the oci_connect function:

    In addition to what was said to fix the problem, I would like to add the php CLI side of things, as some people need to run OCI-enabled applications in CLI mode. In my case, I had to copy an instance of oci.dll into the wamp/bin/php/php / folder for php —ri oci8 to show that oci8 was correctly loaded. That doesn’t prove that other files were not needed to correctly run a full-fledged application (see my technical footnote). Including the path to the instantclient 12 distribution wouldn’t do it.

    Technical notes: My environment being: Windows 7 + WAMP3 (php 5.6.15, apache 2.4.17), I was, after a number of experiments, able to narrow down the minimal set of three files that needed to be copied to the bin directory (Apache’s for non-cli apps) from the instantclient 12 distribution, to allow instantiate an Oracle adapter within Zend Framework, perform an SQL query and read the recordset.

    Fatal error: Call to undefined function mb_detect_encoding()

    I receive this error after trying to set up LAMP by following this tutorial, and I find myself receiving the above error after trying to set up phpmyadmin.

    Fatal error: Call to undefined function mb_detect_encoding() in C:\WebServer\Apache\htdocs\phpmyadmin\libraries\php-gettext\gettext.inc on line 177

    When I run phpinfo() , I see that support for MySQL and mb_string are enabled as shown below:

    11 Answers 11

    Install the gd library also.

    There’s a much easier way than recompiling PHP. Just yum install the required mbstring library:

    Oh, and don’t forget to restart apache afterward.

    Mbstring is a non-default extension. This means it is not enabled by default. You must explicitly enable the module with the configure option.

    In case your php version is 7.0:

    In case your php version is 5.6:

    On Windows open the file php.ini and make this changes:

    Remove the comment and point to the ext directory

    ; extension_dir = «./» -> extension_dir = «C:/Php/ext»

    Remove the comment of this extensions

    Restart apache service

    httpd -k restart

    When I opened my php.ini file, «extension_dir» line looked like following :

    which i changed to:

    Under Windows / WAMP there doesn’t seem to be any php_mbstring.dll dependencies on the GD2 extension, the MySQL extensions, nor on external dlls/libs:

    Whatever php_mbstring already needs, it’s built-in (statically compiled right into the DLL).

    Call to undefined function mb_detect_encoding()

    This error is also very specific and deterministic.

    The function mb_detect_encoding() didn’t fail because php_gd, php_mysql, php_mysqli, or another extension was not loaded; it simply was NOT found.

    I’m guessing that all the answers that are reported as valid (for Windows / WAMP), that say to load other extensions, to change php.ini extension_dir paths (if this one was wrong to begin with, NO extensions would load), etc, work more due to a) un-commenting the extension = php_mbstring.dll line, or b) restarting Apache or the computer (for changes to take effect).

    On Windows, most of the time the problem is that php_mbstring.dll is either:

    Blocked by Windows. Unblock it by right-clicking it, check Properties.

    Оцените статью