![]() |
|||
PHP
IT Tags
Xampp photo gallery local server Stop Script control panel mysql server local server my_thread_global_end include server shutdown indexing solr Remove Duplicate Mobile site Simplexml Parser SimpleXML Combo box associative arrays Overlapping Layers sdf ajax Solr XML connection to MYSQL objects PHP and FLash multiple file uplo UPDATE php mail magento ecommerce check domain XHTML |
Instantiating objects in php
By: Sunil | 22 Sep 2008 2:18 pm
Hi everyone. I'm a .Net developer and brand new to php. I've read <?php include 'StringBuilder. php'; class ThisClass($someVar) public function SomeFunction( ) ?> } I had to fix this by placing the object instantiation within a function <?php include 'StringBuilder. php'; class ThisClass($someVar) public function SomeFunction( ) $sb.append(' Text'); ?> } I suppose the best way to handle this is to instantiate the object in Comments
Hey dude
you can not pass parameters to class as you have done like class ThisClass($someVar) insted you can create a constructor and then pass while you create the object of the class as given below ============ ===== this_class.php class ThisClass() { public function __construct( $comeVar) { private $sb = new StringBuilder( ); } public function SomeFunction( ) { $sb.append(' Text'); $sb.append(' Text'); return $sb->toString( ); } } ------------ --------- ---- this_class_caller. php //initiate teh class object of the TestClass $_this_cladd = new ThisClass($someVar) ; print ($_this_cladd- >SomeFunction) ; ============ ====== Let em know if u need anything else Regards
By: Manoj | 22 Sep 2008
|
