Tag Archives: class

How to call a closure that is a class variable?

Questions: class MyClass { var $lambda; function __construct() { $this->lambda = function() {echo ‘hello world’;}; // no errors here, so I assume that this is legal } } $myInstance = new MyClass(); $myInstance->lambda(); //Fatal error: Call to undefined method MyClass::lambda() So what is the correct syntax for reaching class variables ? Answers:

Zend Framework: Model class not found

Questions: The following exception is thrown on my server: Fatal error: Class ‘My_Model_Bo_User_Agenda_Doctors’ not found in… Though in localhost everything is working fine. I checked that everything was correctly uploaded; all the files are present and not corrupted. I also tried to upload several times. So this doesn’t seem to be the problem. Any idea… Read More »

How to use $this in outside of class?

Questions: Can we use $this outside of class. Please look at the example below, <?php class Animal { public function whichClass() { echo “I am an Animal!”; } public function sayClassName() { $this->whichClass(); } } class Tiger extends Animal { public function whichClass() { echo “I am a Tiger!”; } public function anotherClass() { echo… Read More »

Controller class not found in Laravel 4

Questions: I have the following error while trying to run my controller Controller class not found I have this code in my routes.php file Route::get(‘cms/create-page’, ‘AdminCMSController@create_page’); Route::post(‘cms/createpage’,’AdminCMSController@createpage’); Route::controller(‘cms’,’AdminCMSController’); And this is the code in my Controller class AdminCMSController extends BaseController { public function create_page() { } public function createpage() { } } How can I… Read More »

PHP PDO class programming:Fatal error: Call to a member function fetchAll() on boolean

Questions: I am new to the class programming in php ,Here is my database class. class Database { private $_connection; private static $_instance; //The single instance private $_host = ‘localhost’; private $_username = ‘root’; private $_password = ”; private $_database = ‘admission_portal’; //connect to database public function connectDb() { try { $this->_connection = new \PDO(“mysql:host=$this->_host;dbname=$this->_database”,… Read More »

Expose “use” classes to Included file

Questions: Example: namespace Somenamespace; use Somenamespace\Someclass; use Somenamespace\otherclass; class Template{ public function display($templ){ load_template($templ); } } function load_template($file){ unset($file); require func_get_arg(0); } $template = new Template(); $template->display(‘file.php’); Now I want to access “Someclass” in file.php, without having to declare it first in the “use” statement. eg. someclass::dostuff(); (without the namespace) Is it possible? Answers:

PHP reserved words as namespaces and class names

Questions: Recently I’ve started converting my framework to use the php namespaces and one question to which I can’t seem to find the answer is – is it ‘legal’ to use reserved words such as ‘Object’, ‘Array’, ‘String’ as namespace and class name within that namespace? An example would be: namespace System\Object; class String {… Read More »