Tag Archives: PHP - Page 2

Zend Bootstrap “Circular resource dependency detected” error

So you have also got it :)? This is one of the more strange errors in the Zend Framework if you ask me. One way to get it is to give the init function the “wrong” name in the bootstrap class:

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
    
    protected function _initAutoload() {
        $loader = new Zend_Application_Module_Autoloader(array(
        'namespace' => 'Application',
        'basePath' => APPLICATION_PATH
        ));

        return $loader;
    }

    protected function _initDbAdapter() {
        $this->bootstrap('db');
        $db = $this->getResource('db');
        Zend_Registry::set('db' , $db);
    }

    protected function _initConfig() {
        Zend_Registry::set('config', $this->getOptions());
    }  
    
    protected function _initTranslate() {

        $this->bootstrap("translate");
        $translator = $this->getResource("translate");
        Zend_Registry::set('translator', $translator);
    }
 
}

You see something wrong here? I didn’t 🙂 But there is a problem with ‘initTranslate()’ function. The last part of the name is ‘Translate’ which is the same as the

$this->bootstrap("translate"); 

call. If the bootstrap call is ‘translate’ you can not name the init function ‘Translate’ (case does not matter) so you have to do this:

protected function _initTranslator() { // not '_initTranslate'

        $this->bootstrap("translate");
        $translator = $this->getResource("translate");
        Zend_Registry::set('translator', $translator);
    }

Now the name of the function and the bootstrap call are different from each other which should make the error go away

Hope this saves someone some time. Tested in Zend Framework 1.10

PHP check what modules are installed (cli)

I move around a lot between servers in my line of work so a quick way to see what modules are installed is very valuable. You can of course use the built in phpinfo() function but that requires a browser and web server. A quicker way for me is to use the command line interface.

Simply input on the command line:

php -m

and all the installed modules will be displayed.

Example output:

[PHP Modules]
bz2
calendar
ctype
curl
date
dbase
exif
ftp
gettext
gmp
hash
iconv
libxml
mime_magic
mqseries
openssl
pcntl
pcre
posix
pspell
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xml
xmlrpczlib

String concatenation in PHP

This can be done many ways in PHP. I’m here going to show my two preferred ways:

My personal favorite:

echo string1, string2, string3

Example:

$score = 5;
echo "You scored ", $score, " points!";

Will print:

You scored 5 points!

Using print and dot syntax:

print string1.string2.string3

Example:

$score = 7;
print "You scored ".$score." points!";

Will print:

You scored 7 points!

I try to use the first syntax as much as possible because I believe that it is easier to read in code. Trying to keep it simple