Title: __construct()
Last modified: August 19, 2016

---

# __construct()

 *  [mlotfi63](https://wordpress.org/support/users/mlotfi63/)
 * (@mlotfi63)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/_construct/)
 * why **__construct()** doesn’t work in a wordpress plugin?
 * Check the codes below. This work correctly as a php code, but doesn’t work as/
   in wordpress plugin:
 * >  <?php
   >  /* Plugin Name: myClass Plugin URI: Description: myClass Version: Author:
   > Author URI: */ class myClass { function **__construct()** { echo(‘this is __construct’);}}
   > $myClass = new myClass(); ?>
 * **Please Help, Thanks…**

Viewing 7 replies - 1 through 7 (of 7 total)

 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/_construct/#post-1283571)
 * add `exit;` below the echo and see what happens. Sometimes with WordPress you
   have to kill the script to see echoed output.
 *  Thread Starter [mlotfi63](https://wordpress.org/support/users/mlotfi63/)
 * (@mlotfi63)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/_construct/#post-1283697)
 * **ECHO **is not important, running **__construct()** function is importance, 
   could you help me?
 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/_construct/#post-1283700)
 * > ECHO is not important, running __construct() function is importance, could 
   > you help me?
 * Not if you don’t pay attention.
 * Of course the echo isn’t important! Seriously…
 * You think the __construct() doesn’t work because you don’t see the echo right?
   But as I explained to you before, sometimes you have to kill the script to see
   the echo. I can’t remember the exact circumstances but I have ran into the need
   to kill the script to see the debug data. In other words, you might not be seeing
   the echo even if the __construct works. So do what I said and put the exit below
   the echo and see what happens. If script breaks then the construct works and 
   your problem is elsewhere.
 * That said, I just copied your code into my plugins directory and, well, it works.
   I see ‘this is __construct’ at the top of the page. You did activate the plugin,
   right? And you are running PHP5 and not PHP4, right?
 *  Thread Starter [mlotfi63](https://wordpress.org/support/users/mlotfi63/)
 * (@mlotfi63)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/_construct/#post-1283711)
 * Doesn’t work, even by killing the script.
    I’m using PHP5, (PHP 5.2.8) and WP
   2.8.6 Thanks….
 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/_construct/#post-1283713)
 * Do you mean that the script died and you still didn’t see the echo? Or that nothing
   happened? Or…?
 * I don’t think it is the __construct. Like I said, your code works for me. I copied
   your code from above, pasted it into myclass.php in my wp-content/plugins folder,
   activated the plugin and it works. ( I’m using PHP 5.2.5 and WP 2.8.6, but it
   also works on 2.8.5. )
 * There must be something else causing the problem. Can you get anything to work?
   Can you cause a syntax error, for example?
 *  Thread Starter [mlotfi63](https://wordpress.org/support/users/mlotfi63/)
 * (@mlotfi63)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/_construct/#post-1283715)
 * hmmmmmm, no, I’m using my all wordpress without any problem, all plugins, …, 
   features are working correctly here [http://www.paiz.ir](http://www.paiz.ir) (
   This is Persian [fa_IR]). Even I cleaned up my web server and reinstall wordpress,
   but…
    Off course the ___construct works on my localhost web server in same wordpress
   versions, but on the web not…
 *  [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * (@apljdi)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/_construct/#post-1283716)
 * Which means there is something different about the web hosting environment vs.
   the local server environment. Try to add this function to your class and see 
   what happens.
 *     ```
       function myClass() {
       echo('this is __construct');
       }
       ```
   

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘__construct()’ is closed to new replies.

## Tags

 * [__construct](https://wordpress.org/support/topic-tag/__construct/)

 * 7 replies
 * 2 participants
 * Last reply from: [s_ha_dum](https://wordpress.org/support/users/apljdi/)
 * Last activity: [16 years, 4 months ago](https://wordpress.org/support/topic/_construct/#post-1283716)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
