Yii::import Question

I have a question about this passage from "Agile Web Application Development with Yii 1.1":

[b]The Yii::import method allows us to quickly include the defnition of a

class. It differs from include and require in that it is more effcient. The

class defnition being imported is actually not included, until it is referenced

for the frst time. Importing the same namespace multiple times is also

much faster than include_once and require_once. Also, it is good to

note that when referring to a class defned by the Yii Framework, we do not

need to import or include it. All core Yii classes are pre-imported.[/b]

First question, how is the include not actually made until the class is referenced? Is there a parsing of the source code done before execution?

Second question, what does it mean to import the namespace multiple times, and why is this faster than include_once?



  1. No additional parsing. See http://php.net/manual/en/function.spl-autoload-register.php

  2. You can require_once the same file multiple times. Same way you can import class multiple times. When using require_once file is parsed at call time. When using Yii::import file is parsed when you actually creating a class. So you can probably save a few file parses.