LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-30-2010, 09:29 AM   #1
action_owl
Member
 
Registered: Jan 2009
Location: 127.0.0.1
Distribution: Fedora, CentOS, NetBSD
Posts: 115

Rep: Reputation: 17
Php and Variable Class Names


How can I handle the situation below so that the "Fatal Error" message is not shown. It would be ideal if I could supply a default class to be used. I'd prefer to not use: ini_set() to supress the errors but actually be able to "handle" the error.

Any suggestions?

Thanks

Code:
<?php

	class MyClass
	{
		public function __construct()
		{
			echo 'constructed';
		}
	}

	$class = 'NotAClass';

	$thisClass = new $class();

	// Fatal error: Class 'NotAClass' not found

?>

Last edited by action_owl; 09-30-2010 at 09:51 AM. Reason: SOLVED
 
Old 09-30-2010, 09:48 AM   #2
xDan
LQ Newbie
 
Registered: Sep 2010
Posts: 6

Rep: Reputation: 1
You could check with class_exists before calling it.
 
Old 09-30-2010, 09:51 AM   #3
action_owl
Member
 
Registered: Jan 2009
Location: 127.0.0.1
Distribution: Fedora, CentOS, NetBSD
Posts: 115

Original Poster
Rep: Reputation: 17
Perfect, Thanks xDan.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP: Calling class functions from another class. unreal128 Programming 5 11-24-2006 03:04 AM
stringstream as class member variable xhi Programming 15 10-13-2006 11:52 AM
C++: difference between static method variable and static class variable? Thinking Programming 3 01-16-2006 10:08 AM
Unique class names (C++) ToothlessRebel Programming 6 12-25-2004 12:16 AM
PHP: how to use a method from a class in the same class ldp Programming 5 09-17-2004 09:52 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration