Assign Function To Class....
Is it possible to assign some functions to a of a class?
class loginClass {
function initialize() {$something}
}
function CheckLogin() {
$something
}
$login = new loginClass();
$login->onLogin = CheckLogin();
$login->initialize();
where the CheckLogin function will only be run during the initialize of the class, not during loading of the whole document.
View Complete Forum Thread with Replies
Related Forum Messages:
Assign Class Variables
I have a class with several variables, and I need to set them. I want to do them in a loop instead of assigning variables one at a time. How do I do that? Keep in mind that some animals don't have certain features, like wings, so those classes don't have wings as variables. The reason I need to do that is because I have many animals besides dog, and I am doing same thing over and over again in each different php file for each animal. I am trying to combining them into one php file. class dog { var ear; var tail; var eye; } dog = new dog; dog->ear = 1; dog->tail = 1; dog->eye = 2;
View Replies !
Is It Possible To Assign A Whole Function Or Block To A Variable ???
Is it possible to assign a whole function or block to a variable ??? eg. <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre> <? if (db_num_rows($qid_p) == 0) { ?> <li>No <? } ?> <? while ($prod = db_fetch_object($qid_p)) { ?> <p><b><a href="product_details.php?id=<?=$prod->id?>"><? pv($prod->name) ?></a></b> <br><? pv($prod->description) ?> <br>$<? pv($prod->price) ?> <br>[<a href="cart_add.php?id=<?=$prod->id?>">+ Add to Cart</a>] <? } ?> How to assign this code to a unique variable ???
View Replies !
Assign Function Output To Variable??
I've found some references to this topic at : http://forums.devshed.com/showthrea...ion+to+variable but it does not seem to be working for me. here's a snippet... <? PHP function listPeople ($getArray) { foreach ( $getArray as $val ) { echo "$val, "; } } $foo = listPeople($splitDirector); ?> The function works, and as you can see i'm simply trying to assign the output of the function to $foo. But instead, the output is written to the page where I assign it... like a print or echo statement, and the variable $foo is empty.
View Replies !
Assign MySQL Function Result To PHP Variable
I know to use: mysql_fetch_row($result) to convert a row from a SQL query result set into an array for use with PHP. but in the case of SQL queries that return one value, such as calls to MySQL functions, is there another PHP mysql api function I should use. For example, right now I use a "workaround" technique from PHPBuilder: $result=mysql_query("SELECT COUNT(*) FROM tablename"); list($numrows)=mysql_fetch_row($result); Rather than using this "workaround" code is there a way to simply assign the result of the MySQL function query to a variable. $result=mysql_query("SELECT COUNT(*) FROM tablename"); $numrows=mysteryfunction($result);
View Replies !
Access Class Member Function Without Instantiating Class?
I need to access a class member function from outside the class, and hopefully without having to instantiate the class if possible? I have an HTML form <select> and each <option> item is being pulled from an array stored in a mysql db. But I'm doing this independently of the normal purpose of the class itself, I just want to use that member function.
View Replies !
Invoke Function From Initiated Class Within A Class
<?php //clsrecordset.php class Recordset extends Database{ public function Recordset( ) { } public function query( ) { } public function endOfFile ( ) { } } ?> <?php //clssearchindex.php require_once('clsrecordset.php'); class Searchindex { private c_rs; public function Searchindex ( ) { $this->c_rs = new Recordset( ); } public function getSQL ( ) { } public function getData ( ) { $rs = $this->c_rs->query($this->getSQL()); // error occurred this line $this->c_rs->query($this->getSQL()); if ( $this->c_rs->endOfFile() ) { $norecs = true; } } } ?> Error message: Call to a member function query() on a non-object Additional, when I type the $this->c_rs-> , there is no intellisense on this case that's why I know there is something wrong and couldn't find the function. Help: How can I call the function from the initiated class in order to use in other class?
View Replies !
Coding A Class' Function Outside A Class
I still haven't found if there is a way to write functions (methods) that belong to a class, outside of that. Maybe there is not, at least untill now.But I prefered to post a question here about that in case there is and someone knows.
View Replies !
Function Inside A Class Function Dont Pass Variables...
Im using xajax class, and i just made a custom class called mantenimientos that use objects of this xajax class. Something like this: class mantenimiento { public $titulo; public $ajax_sRequestURL; function __construct($titulo,$ajax_url){ $this->titulo = $titulo; $this->ajax_sRequestURL = $ajax_url; } function exec_ajax(){ //Here i can use $this with no problem $xajax = new xajax($this->ajax_sRequestURL); $xajax->registerFunction("call_fun"); //I have to do this to have acces to the class itself when im inside a function global $mant ; $mant = $this; function call_fun(){ //next line give me access to the mantenimiento class properties. //I havent found other way of doing it. global $mant; $objResponse = new xajaxResponse(); $objResponse->addAlert('XAJAX CALLED:'.$mant->titulo); return $objResponse->getXML(); } $xajax->processRequests(); } My problem is that $mant->titulo lost it value when i im inside the funciton, but only when that value comes from other var. for example: if i do this: $mant = new mantenimiento('This is the title','index.php'); or $titulo = 'This is the title' $mant = new mantenimiento($titulo,'index.php'); When i execute the xajax_call_fun, it shows an alert box with the text "XAJAX CALLED:This is the title" but if i do something like this: $titulo = gettitulo_from_database(); or $titulo = $_POST['titulo']; The alert box show the mensaje with out the value of the $mant->titulo Im getting crazy with this....!
View Replies !
Using A Function Within A Class
I have written a class (and it works!). Now I want to tidy the code a bit by separating some subroutines and I get a "Fatal error: Call to undefined function:" e.g. class Fred{ function Fred(){ //constructor do_this(); } function do_this(){ blah blah } } Please can someone tell what I'm doing wrong? If I use function_exists(do_this) it returns false. I've tried putting the function as the first block in the class. I've tried calling it as a method e.g. $this->do_this(); PHP 4.3.9 on IIS (localhost)
View Replies !
Class ..function
I am headach with PHP5 now. I am trying to write this code as class or function but I am sure how to write it. PHP Code: <?If(!isset($id))    {header("Location:home.php");}     else       include("connect.php"); $sql="select * from web where webID=$id"; $result=mysql_query($sql); $row=mysql_fetch_array($result);?> <FORM METHOD="post" ACTION="EditProfiles_Save.php" ENCTYPE="multipart/form-data"> Your E-mail Address::<INPUT TYPE="text" value="<?=$row["MyEmail"]?>" NAME="email"><br> Password::<INPUT TYPE="password" value="<?=$row["MyPassword"]?>" NAME="password"><br> Display Name::<INPUT TYPE="text" value="<?=$row["MyDisplayName"]?>" NAME="displayname"><br><br><br> .................
View Replies !
Creating A Class To Do A Function
I am creating a class to do a function that will be used a lot on my site. The problem i am having is i dont want to redefine a function that i already have defined in my functions.php page. is there a way that i can reference the funtion in side the class? do i just global the function? or is this even posible.
View Replies !
Passing A Class To A Function...
if I have something like, (still using PHP <5) function c( &$obj_someclass ) { // do more work on it $obj_someclass->SomeFunction(); } function a() { $z = new CSomeClass // work on $z c( $z); } I get an error 'cause function c does not know that $obj_someclass is of type CSomeClass How could I do the above? or must I declare it global?
View Replies !
Output Class Function To $var
I am having a bit of a problem with my first class. In general there is a function named "table" in my class that I wish to retrieve a string of info from to be passed on to fasttemplate. PHP Code:
View Replies !
BUG: Referring To A Class Function
This is a "namespace" problem with "::". Is there an official place I can report php bugs? I'm new to PHP (and soon to be leaving it): class SomeClass { function dostuff($ar) { uasort($ar, 'SomeClass::somesort'); } function somesort($a,$b) {<-- never gets called echo "Yes I got called"; //<-- never happens if ($a[order] == $b[order]) { return 0;} if ($a[order] < $b[order]) { return -1;}; if ($a[order] > $b[order]) { return 1;}; } } SomeClass::dostuff($ar); //put whatever you want in the $ar array to test In the line "uasort($ar, 'SomeClass::somesort');", 'SomeClass::somesort' isn't recognized by PHP. I also tried just 'somesort', no go. I was trying to use a class as a substitute for PHP's lack of namespaces. (Which btw is the reason I'm bailing out of php.) Because of this bug I have to put my sorting funct into the global space, which is ridiculous.
View Replies !
Class Or Function For A Key Generator?
I need to be able to produce a string consisting of uppercase letters and numbers. I would also like it to produce e.g. a string of 6 characters all the time. A given number must allways result in same string such as "AE4YX8". Would also be nice if I could go from the string to the original number as well. Anyone with links to sites with example on how to do this?
View Replies !
Pass Var From One Function To Another In Class
Im getting a var sent to one function. Which I need to use in another function within a class. This is double right? The var can be seen in the first function under the name $num2,.. and then I try to use it again under the rows function,.. I will attempt to highlight this var in black... Code:
View Replies !
Using Class Inside A Function
I'm trying to utilize a class from inside a function. I've set an object of the class outside the function and inside the function, when outside did not work. The error for outside the function is "Fatal error: Call to a member function on a non-object in generate.php on line 103". The error for inside the function is: "Fatal error: Call to undefined function: query() in generate.php on line 100". I don't understand what is wrong. Can anyone help?
View Replies !
Class, Function, Switch
I have a class, with a function that contains a switch and is called within a "while" When I made it I obviously did not think that being in a "while" I will trigger the "Cannot redeclare class.." error How may I get around . of course I could reverse it to "procedure" instead of OOP but I would like finding a solution . I guess the real question is what should be the logic to utilize a class called within a "while" . when I read what I wrote it seems like no way out.
View Replies !
Handling Class And Function
i have a script for displaying the records from mysql table along with checkboxes to delete the multiple records from table. what i want is i want to put the code inside one class and one function.that's all.but when i put the code in class & function the record is not deleting but when i remove the class & function the record is deleting. Code:
View Replies !
Class Calling Function
I have a function called getName() in a class called info. Then I have another function called getDropDown() in a class called adminFunctions. Now; I include these two classes into a normal php page called "category.php" like this: include("info.class.php"); $info = new info; include("admin.class.php"); $theAdmin = new adminFunctions; I have is how would I call the getName function in the info class from the getDropDown function in the adminFunctions class. I know when calling a function in the same class I would use $this, but I'm not sure about calling from a different class.
View Replies !
Help With Function Call From A Class
how do i call a function from within a class. the function that I'm trying to call is a function defined in another file that I've included in this file. example: In file1.php ********* function call_me() { } In file2.php ********* include('file1.php') class caller { function foo() { call_me(); // this doesn't work, I get a fatal error when i do this. } }
View Replies !
Function To A Class Dynamically
I don't see anyway of adding a function to a class dynamically. I wrote a class like this PHP Code: class bcext{ function __construct(){ $this->bcext(); } function bcext($load = 1){ if($load == 1){ $dir = scandir('plugin/'); foreach($dir as $key => $var){ if($key != 0 && $key != 1){ include('plugin/'.$var); } } PHP Code: function foo(){ echo 'bar' }
View Replies !
5 Naming A Function In A Class
I am retrofitting my CMS OOP to suit PHP5 in my class I use: public $foo public $foo2 etc.. then there are many functions Question: Should the function's name start always by for ex: public function getMode() { #*$!xx } or even private or protected to match $foo prefix the question is triggered by reading Zend tutorials that does it.
View Replies !
Class Public Function
I am running PHP version 4.3.11-dev: The class as defined below does not work: <?php class hello { public function printHello() { echo "HELLO"; } } $obj = new hello; $obj->printHello(); // does NOT print hello ?> When i delete the 'public' keyword then the above works ok! Is it maybe because 4.3.11-dev probably does not fully support classes?
View Replies !
Database Query From Within A Class Function
My application is object orientated and each object requires a cooresponding "PageID" in the tables "Page" and "PageContent" as well as a few other necessary elements to display properly as a web page. Some page elements are contained in their own tables, but are associated with the"Page" and "PageContent" tables by the "PageID" that cooresponds to the page the element should be displayed on. I have written a script that allows me to create a new page by inserting data into fields on the "Page" and "PageContent" tables, but it only works as long as the "PageID" in each table is auto_incrementing in sinc. I wanted include a method for members to sign-up for the site and I fould a script named "Authlib v1.94" that seems to work pretty well on its own. However, I hacked the code to redirect the data to an existing member table and cut out some of the validation. My intital tests on the hack have been satisfactory. If any of you are familiar with the "Authlib v1.94" code you may be aware there's a file named backend.php included in the script. It is a class file that includes some pretty nice validation functions for dealing with registering new members, logins, etc. The register function of the authlib class validates user input from the regestration form. If all the checks pass, it goes on to create a new entry in the "Member" table. (Keep in mind that I redirected the data to this table and hacked the code a bit.) The code looks something like this: PHP Code:
View Replies !
Session Variable Within Class Function
Background info: the application I'm working on has register globals enabled. session_register is used to establish the session variable in every page (via included file). How do i access that session variable from within a class? I've been doing some reading and all I've determined is that using session variables within classes is tricky businesses.
View Replies !
Ob_start And A Callback Function In A Class?
i want to use a callback function for my ob_start inside of a class. but it wont work in any way. ob_start("bar") works fine if the function is not in a class. ob_start("$foo->bar") or ob_start("Foo::bar") doesnt. Is there a way to use a function inside of a class for a callback?
View Replies !
Join Function In A Class Template
Below are snippets from a routine that runs queries on the database, processes the information through a PHP class ("HtmlTemplateClass.php") and then outputs the applicable output on an HTML template ("TopNewsTemplateP1.php"). It all works except for the $Page->SetParameter ( "PUBLISHED_ARTICLES", join(" ", $NoArticles) ); part. The $Admin[] "join" function and the $Reporter[] "join" functions work fine. However, they are both arrays. The $NoArticles "join" function does not work. Obviously, the $NoArticles variable is not an array so I need to treat the $NoArticles variable different than the $Admin[] and $Reporter[] array variables. Can someone tell me how to write the snippet to replace the join("", $NoArticles) below? (Note: For some reason the "newline" backslash is not appearing before the "n"'s below on this posting.. ?) PHP Code:
View Replies !
How To Access A Function Of A Parent Class ?
if i access a function of a class, i do this : $x=new Class; $x->function(); how do access a function of a parent class ?..let's say, class "Class" has a parent class "Parent" and "Parent" has a function n(). how to access n() from Class above ?
View Replies !
Return A Variable From Class Function
I have been working on something that should be simple but I cannot figure out how to do it. Basically, I am working with a PHP class that handles MySQL queries. The code to call a query looks like looks like: $dbcn->db_qry("DELETE FROM contactus WHERE id='$id'","1"); This function is inside a class called db_connect. The function is function db_qry($qry, $type, $from="") { $this->dbQryResult = mysql_query($qry) or $this->goError($qry, mysql_error(), $type, $from); } As the function shows, if the query fails, it is directed to the goError() function where it prints an error message. The problem is that some instances, I want it to instead return a variable back out of the function. The variable holds some information so I can print out the error message later in the page. In this case, it should return a variable indicating whether the query succeeded. That variable will be used in the following part: Code:
View Replies !
Variable Class Function Names
I have a class that may have a lot of relationships and I would like to do something like this... public function getRelated<classname>(){ // Whatever logic } But I want <classname> to be variable...for example getRelatedBooks getRelatedArticles, each class has his own relationships. Can that be done?
View Replies !
Use Validation Class With Callback Function?
I am making a php multipage form. For each $_POST and $_GET for the form, I have a seperate class for validating each variable. I have a single function that deal with all form general validation. I don't want to "new" each class because it will lower the performance a lot. I want to do call_user_func_array( ), and then pass each class's validate function into it. Is it a good idea? Will it have lower performance than just using pure function? Code:
View Replies !
Code Not Running When Comes To Class Or Function
I am new to php. Currently i have tried some simple coding. I tried to code some simple class and function in php. Yet it does not running. Those print statement before the class coding are shown. I am using Apache2Triad1.4.4, supporting php 4.4.2, php API version 20020903. Code:
View Replies !
Function Private To A Class Method
PHP Code: class myclass    {    function doit()       {     $result=dosub($somevalue);       }       function dosub($somevalues)         {         // some sub actions           }       } the problem is now it is possible access the function from the calling program too,like, PHP Code: $myobj->dosub();
View Replies !
PHP5 Class - Call To Undefined Function Sum()
Dear All, I have problem with the class I use class in PHP5 like this: <? calss myPHP{ function sum($x,$y){ return $x+$y; } function all($a,$b,$str){ $total=sum($a,$b); return "$str=$total"; } } ?> the error have show : call to undefined function sum()
View Replies !
Use Function In Class W/ Custom Error Handling
I'm trying to set a function that is held within a class as the custom error handler using the set_error_handler(), which takes the string name of the custom error function as its argument. I fully understand this, however, how do you use a function that is declared within a class? PHP Code:
View Replies !
Splitting Class/function Declarations & Definitions
Is it possible to split-up a class declaration and its' functions definitions? By this I mean the same idea as in C++ with header and source files. Having to define my functions within its class declaration is clumsy and untidy, made worse by larger classes and functions. PHP Code:
View Replies !
PHP5.1.6: Class DateTime Not Found / Undefined Function Date_create
I am using PHP 5.1.6 on RHEL5 server (is default installation of PHP). When using DateTime I get a fatal error: Class DateTime not found, the same with the function date_create: call to undefined function. According to the PHP manual DateTime and date_create are available from PHP version 5.1.0. The development machine uses PHP 5.2.1 (everything works fine), but...
View Replies !
Cannot Re-assign $this ...
I'm one more guy having the cannot re-assign $this problem. someone left a php4 file here containing the lines |function linkbar() |{ |if(func_num_args() == 1) |{ |$this = func_get_arg(0); |return; } ... |} inside a php4 class definition. func_get_arg(0) in this case delivers an object - working fine in php4. I struggled a bit with the & referencing (while not really understanding it and the problem) but gave up. how must I modify the code to get it to work in php5?
View Replies !
Defining A Class/instantiating Object Inside A Method Of Another Class
I have a class. Inside the class I have a method that reads a text file. In the text file I have a class name and a file name where that class is defined. Now, I need to instantiate an object of that class, the problem being that at the time I find out the class name and the file name, I'm inside a method of another class. Well, let me just type up a little example:
View Replies !
|