You can write a class with a collection of hard-coded usernames and associated passwords. You might make these constants or assign them in the class constructor. But what would this class be useful for?
Only the instance would be hard coded.In object-oriented programming, instance is a term of art. In PHP terminology, it is the object that is made from a class definition, when you instantiate the object by running the class constructor, using the keyword "new." As such, it exists only in memory, and not on paper. In other words, it cannot be hard coded because it does not exist until after the PHP interpreter has begun to run the PHP instructions in the script.
Are you working on some kind of online example or tutorial that you can tell us about?
A class can be hard-coded. But that would probably only be done if you were writing an abstract class and had plans to extend it with working methods.
// next create your Name Array
$input = array('user1','anotherUser', 'anotherUser2','bob');
foreach ($input as $uName) {
//from a config file. I decided to create object this each time to initiate the constructor
$m_instance = new mam($config);
$m_instance->default_username=$uName;
// works if all the users have 'password' as their password
$m_instance->default_password='password';
$m_instance->method();
//just to make sure that the instance is destructed
unset($m_instance);
// needs } at the end of code to close the foreach
}
class mam
{
public $dbh = NULL;
public $default_username = '';
public $default_password = '';
public $action = array();
public $chosen_action = 0;
public $log_file = '';
public $db_type = '';
public $db_hostname = '';
public $db_port = '';
public $db_name = '';
public $db_username = '';
public $db_password = '';
public function __construct($config = array())
public function doAction()
//case statements to call class functions
//class functions can also be called outside class by creating object
public funciton deleteMessage($default_username = '', $arr_profile_id_or_sql = array(), $arr_sql_params = array())
public function ConvertDateTime($date_time_str = 'now')
//Ray wrote this converting written time to mysql time (so I do not need varchar column, I can use mysql datetime
public function EchoMessage($default_username = '')
//saves message into the database
public function ProfileName($default_username = '', $arr_profession = array())
//lists profile_id and profession but does not save information to database yet
public function ParseProfile($default_username = '', $arr_profile_id_or_sql = array(), $arr_sql_params = array())
//gathers attributes about profile_id and stores to database
public function ParseProfile2($default_username = '', $arr_profile_id_or_sql = array(), $arr_sql_params = array())
//updated class of ParseProfile
//gathers attributes about profile_id and stores to database
<?php
error_reporting(E_ALL);
class Thing
{
public function __construct($config = array())
{
/* CODE FOR THE CONSTRUCTOR HERE */
}
public function doAction()
{
/* CODE FOR DOACTION() HERE */
}
}
class mam
{
public $dbh = NULL;
public $default_username = '';
public $default_password = '';
public $action = array();
public $chosen_action = 0;
public $log_file = '';
public $db_type = '';
public $db_hostname = '';
public $db_port = '';
public $db_name = '';
public $db_username = '';
public $db_password = '';
public function __construct($config = array()){
//does something with a cookie of which I do not understand
}
public function doAction(){
//case statements to call class functions
//class functions can also be called outside class by creating object
}
public funciton deleteMessage($default_username = '', $arr_profile_id_or_sql = array(), $arr_sql_params = array()){
}
public function ConvertDateTime($date_time_str = 'now'){
//Ray wrote this converting written time to mysql time (so I do not need varchar column, I can use mysql datetime
}
public function EchoMessage($default_username = ''){
//saves message into the database
}
public function ProfileName($default_username = '', $arr_profession = array()){
//lists profile_id and profession but does not save information to database yet
}
public function ParseProfile($default_username = '', $arr_profile_id_or_sql = array(), $arr_sql_params = array()){
//gathers attributes about profile_id and stores to database
}
public function ParseProfile2($default_username = '', $arr_profile_id_or_sql = array(), $arr_sql_params = array()){
//updated class of ParseProfile
//gathers attributes about profile_id and stores to database
}
}//close class
I would avoid copying and pasting any code I did not completely understand!I really dont understand the code but I can call the methods and set properties
You can write a class with a collection of hard-coded usernames and associated passwords. You might make these constants or assign them in the class constructor. But what would this class be useful for?