Symfony and Ioncube

This article has moved to this location.

In symfony, encoded classes excluded from config_autoload_yml.php. Because when symfony found the classes and read the contents, symfony can not find the words that contain abstract class|interface, final class|interface, class (preg_match_all(‘~^\s*(?:abstract\s+|final\s+)?(?:class|interface)\s+(\w+)~mi’, $content, $classes);).

There is an easy way that can be used, although this method has some shortcomings. I’m using Symfony version 1.3beta, but in symfony 1.2 or 1.3alpha it can be applied.
Let’s get started…

  1. Create config_handles.yml file, and put it in project config folder (sf_root_dir/config)
      class: mysfAutoloadConfigHandler
  2. Create mysfAutoloadConfigHandler class that extends sfAutoloadConfigHandler, override parseFile() function, and put it in the same folder with config_handlers.yml (sf_root_dir/config)
    class mysfAutoloadConfigHandler extends sfAutoloadConfigHandler
      static public function parseFile($path, $file, $prefix)
        $mapping = array();
        $content = file_get_contents($file);
                             $content, $classes);
        if (count($classes[1]) == 0)
          if (stristr($content, 'ioncube_loader') !== FALSE)
            $explodes = explode('/', $file);
            $classphp = $explodes[count($explodes)-1];
            $classnames = explode('.', $classphp);
            $classname = $classnames[0];
            $classes = array('', array($classname));
        foreach ($classes[1] as $class)
          $localPrefix = '';
          if ($prefix)
             // FIXME: does not work for plugins installed with a symlink
             preg_match('~^'.str_replace('\*', '(.+?)', preg_quote(str_replace('/',
                             DIRECTORY_SEPARATOR, $path), '~')).'~', str_replace('/',
                             DIRECTORY_SEPARATOR, $file), $match);
             if (isset($match[$prefix]))
               $localPrefix = $match[$prefix].'/';
          $mapping[$localPrefix.strtolower($class)] = $file;
        return $mapping;
  3. Edit setup() function in ProjectConfiguration.class.php file

    public function setup()

But, the solution i proposed above still have some disadvantages:

  1. Not just Class files, Helper files are also included in config_autoload_yml.php
  2. Class name must have the same name with file name, for example: if you have a class named A (Class A), then your file should be named A (A.class.php)

Symfony libraries, log, cache and all the files in the config folder (project config folder, application config folder and modules config folder) is left unencrypted.

9 responses to “Symfony and Ioncube

  1. Hector Perez Hernandez April 27, 2010 at 2:11 am

    hola amigo, estoy tratando de ofuscar un proyecto realizado con symfony, he tratado de hacer todo lo que antes usted menciona pero no me funciona, si tiene alguna guia que me pueda dar se lo agradecería ….
    gracias …

  2. Hector Perez Hernandez April 29, 2010 at 7:51 pm

    I’m working with smfony 1.2.12, and I need to obfuscate the lib directory but when you are loading classes not found, because it is encoded, I tried to experiment with the code above but still can not find the classes, do you can suggest me?
    sorry for my English

  3. Hector Perez Hernandez April 29, 2010 at 7:51 pm

    I’m working with smfony 1.2.12, and I need to obfuscate the lib directory but when you are loading classes not found, because it is encoded, I tried to experiment with the code above but still can not find the classes, do you can suggest me?
    sorry for my English, thanks friend

    • nibsirahsieu April 29, 2010 at 9:20 pm

      I assume you are using ioncube encoder. If you are using another encoder, replace the word ‘ioncube_loder’.
      The version of encoder that i use is ‘’ (linux version). You can get the loader from here.
      Make sure, your class name has the same name with the file name. for example, if you have a class ‘myClass’ (class myClass) then your file name should be myClass.class.php
      If you follow step by step above, i think there’s no problem..
      I’ve been using this in my production for a few months ago, and i’m using the latest symfony 1.4.4 version now.. so far so god, and i still found no problem

      If you still found some errors.. may i see your ProjectConfiguration.class.php? and which files you encoded?. You can post here or send me by email to

      Good luck my friend.. and i’m sorry too for my english.. 😉

      Below is an example of my encoded class (it’s an actions class).

      <?php //003ab
      if(!extension_loaded('ionCube Loader')){$__oc=strtolower(substr(php_uname(),0,3));$__ln='ioncube_loader_'.$__oc.'_'.substr(phpversion(),0,3).(($__oc=='win')?'.dll':'.so');@dl($__ln);if(function_exists('_il_exec')){return _il_exec();}$__ln='/ioncube/'.$__ln;$__oid=$__id=realpath(ini_get('extension_dir'));$__here=dirname(__FILE__);if(strlen($__id)>1&&$__id[1]==':'){$__id=str_replace('\\','/',substr($__id,2));$__here=str_replace('\\','/',substr($__here,2));}$__rd=str_repeat('/..',substr_count($__id,'/')).$__here.'/';$__i=strlen($__rd);while($__i--){if($__rd[$__i]=='/'){$__lp=substr($__rd,0,$__i).$__ln;if(file_exists($__oid.$__lp)){$__ln=$__lp;break;}}}@dl($__ln);}else{die('The file '.__FILE__." is corrupted.\n");}if(function_exists('_il_exec')){return _il_exec();}echo('Site error: the file <b>'.__FILE__.'</b> requires the ionCube PHP Loader '.basename($__ln).' to be installed by the site administrator.');exit(199);
  4. Hector Perez Hernandez May 3, 2010 at 10:13 pm

    thanks friend, your solution is brilliant, and it works, my email is, if you need help someday you tell me, thanks

  5. Rodrigo Traleski October 20, 2012 at 2:38 am

    Hi, good evening! I’m using symfony 1.4. Is the same instructions? I tried that, but it’s not working. I did how you made. Do you have an idea?

Leave a Reply to Hector Perez Hernandez Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: