Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Function Pointer?


Does PHP have anything like a C/C++ function pointer?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Possible To Keep A Pointer To An Object In A PHP Variable?
Is it possible to keep a pointer to an object in a PHP variable? I'd like to
do this :

$obj1 = new myClass(...);
$obj2 = $obj1;
$obj1->name = "foo";
$obj2->name = "bar";

echo $obj1->name;

Which would display "bar" instead of "foo" with the current PHP behavior.

Find Name Of Domain Pointer
I have several domain pointers that point to my main domain. My
hosting company automatically redirects visitors to my main domain, if
a domain pointer is used, but how do I determine which domain pointer
the visitor used to get to my site? I was using
Request.ServerVariables("SERVER_NAME") in asp, but I can't find a php
equivalent.

Pointer Of Mouse And Text Form.
Anybody know wether one can create such text-form that pointer of mouse
will be automatically set in the text field of form? It means that user
can type text immediately after page has been loaded, without putting
pointer of mouse by hand in the text field.

Setting Array Internal Pointer
I was wondering if there was a way to set an array internal pointer to the array element in one step rather than running a loop where you use next() or prev() until you stop at the point you want?

When Is A Database Resource Pointer Not Valid, And What Test Can Be Run?
I posted before, but have now narrowed my problem down to this method.
At the start of the method, I test to make sure that I have a
resource, a pointer to data returned from a database. This test is
coming back true, so the next line runs, which attempts to get the
next row from the dataset. This brings back nothing. On the queries
I'm running right now, the first row will be fetched, but then no
further rows. If I expect 20 rows back, I get one, then 19 errors. I
use phpMyAdmin to run the query in another environment, to be sure of
what I should be expecting..

/**
* 11-04-03 - it is important that the resource which points to the
returned dataset gets passed into this method
* by reference, not by copy, or else, in the outside code that is
calling this method, the pointer in that resource
* will never advance to the next resource row.
*/
function dsRowIntoArrayWithStringIndex(&$dsResult) {
// 11-04-03 - this first lines test to see if anything came back
from the datastore
if (is_resource($dsResult)) {
$row = mysql_fetch_array($dsResult, MYSQL_ASSOC);
$row = $this->stripslashesFromEntryWithKeyIndex($row);
return $row;
} else {
$this->resultsObject->addToErrorResults("In
dsRowIntoArrayWithStringIndex(), in the class McFormatResultsMySql, we
expected the method to be handed a pointer to a database return
resource, but we were not.");
}
}

Mysql Fetch Row Data Without Moving The Pointer
Is there any way to get data from a row without moving the pointer?

File Re-writing And Moving The File Pointer
i have a text file that looks like this:

<bt>600</bt>
<iregno>123123</iregno>
<users>
<un>2</un>
<u1>
<n>Username</n>
<ema>username@domain.com<ema>
<s>password</s>
<t>user type</t>
<p>profile name</p>
<cat>000000000000000000000000000000000</cat>
</u1>
and so on
</users>

Now i run this big user edit function where im reading in their details and displaying them in forms and so on. They then edit the form fields and i read them back in using $POST. That's the easy part. What i then want to do is re-write a section of my text file.

I have a variable that tells me what user i need to re-write the details for, i also have all the new details that i need to replace the old ones with. So, in logical terms, what i need to do is move my file pointer to that section of the file:

read in $userToEdit variable -> output of variable is <u1> -> move file pointer to next line (<n>username</n>) and let me rewrite the next 6 lines therefore leaving the pointer at </u1> I hope that makes sense. Just basically want to rewrite the text that is there, not append/add.

File Pointer At Beginning Of File
The following is taken directly from the PHP quick ref section under fopen.

'r' - Open for reading only; place the file pointer at the beginning of the file.

'r+' - Open for reading and writing; place the file pointer at the beginning of the file.

'w' - Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.

'w+' - Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.

'a' - Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it.

'a+' - Open for reading and writing; place the file pointer at the end of the file. If the file does not exist, attempt to create it.

None of these do what I want though one of them say they will. I need to write input from a form to the beginning of a text file. But when I use $myFile = fopen("file.txt","r+");

it writes to the beginning of the file. But when I execute the script again it writes OVER what was previously there. I need it to INSERT the input from the form. I'm fairly new to PHP so if I've not included some valuable information let me know.

Function Inside An Echo - Function Outputs In Wrong Place?
Why does the function evaluate at the beginning?
Can I prevent this so it outputs in the order in the intended sequence in the echo? PHP Code:

Recover The Agrument Names Passed To A Function Inside That Function? Possible?
Is it possible to recover the agrument names of the arguments passed to a function inside that same function?

example :

blabla($hehe, $huhu, $hihi);

function blabla($a, $b, $c)
{
arg_name($a) = "hehe";
arg_name($b) = "huhu";
// ...
}

Is this possible (agr_name is an imaginary fn)

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....!

Function/Global Var To Return Name Of Calling Function?
I'm sure I saw this somewhere but can't remember where and can't find it now...

Is there a PHP function or global variable that will return name of the calling function? I want to do this for error reporting purposes without
having to hardcode the function name into my scripts.

Say the function is named getFunctionName(). I want to do something like...

function foo() {

Function To Automatically Take/select All Arguments In A Function ?
Is there a function to automatically take/select all arguments in a function ?

Is There A Function In Php Similar To Javascript's SetTimeout Function ?
Is there a function in php similar to javascript's setTimeout function ?

Address Of Function Or A Virtual Function
Is there some way to implement something like a virtual function or
have something like a user defined function ? One solution I thought
might work: store a reference (address) of a function in a variable
and call it later if that variable has been set ? This seems to
compile OK, but produces funny results. Is this outside the scope of
php ?

function testfn()
{
....
return $result;
}

$myfn = &testfn; // set it too the address of the function
....
if (isset($myfn))
$result = @$myfn(); // call my function

Any Function That Works Like Function() But Without GLOBALS?
I could really use something like that. The globals problem really annoys me (I don't want to define all my variables as globals in every single function). I just need to call big chunks of code when I need them.

Variable Scope - Function In Function
Here's something that I can't manage to find explicitly documented. In the
following snippet:

function outer() {
global $a;
function inner() {
global $a;
echo $a.&#391;<br>'
}
$a = 's'
inner();
echo $a.&#392;<br>'

}
outer();
?>

If either of the globals statements is removed, the variable is not
accessable within inner.

Call Function Inside Another Function
I have a function that gives me the difference between 2 dates. I also have another function which compares a couple things and uses the first function. How do I call one function from within another. Here are the 2 functions. Code:

Getting The Function Name Of The Calling Function How?
I guess the Subject is a little ambiguos. I want to get the function
name which calls the target function.
Like
function xxx()
{
....
....
yyy(2,3);
function zzz()
{
....
yyy(5,6);
.....
function yyy($a,$ab)
{
...
...
echo "yyy() has been called by the function - ".$functionname;
Now how can I get the name of the function tat calls yyy()....

Put My Function As Default Function?
I have a function foo(), I want all my page can call this method
without include / require

I know I can set in php.ini by setting the auto_prepend...

but this will cause overhead as every file need to prepend this file
even no call to the function,

are there any better method?

instead of writting an extension?

Function Inside A Function
I have encounter errors on functions inside functions this is what I write. PHP Code:

Call Function From Within A Function (oop)
I've been working on this (simple) MySQL class. It's gone well so far, but I can't seem to call a function from within a function inside the class.

I want to be able to call the safeSQL function inside the executeQuery function, so that everytime I run a query it automatically checks to make sure the "SQL" is "safe".

However, whenever I try to do that, I get this error:

Fatal error: Call to undefined function safeSQL() on line 53
Can't you call a function from within a function in a PHP class?

Dl() Function
Just a short question about his function: if I use it to load the new version of the GD library that supports WBMP, does that mean that I can use the ImageWBMP function to create thos images?? My logic states that this is the case, but if anyone out there has already worked with this function, maybe yu can give me some insights.

What Function?
What function could I use to see if a ' is in a string?

Sum Function
You can see here a script that select the kolom "flighttime" and where a sum function is aplied. ($seltime= "SELECT SUM(flighttime) AS totalflighttime FROM pirep;"

But Now I like to have the sum of flightimes for some people, where the callsign= $callsign.PHP code:
<?php

include("dbconnect.php");
$fldate=date("Y-m-d");

echo $date;



if ($submit == "Sent")
{
$seltime= "SELECT SUM(flighttime) AS totalflighttime FROM pirep;";
$result = mysql_query($seltime) or die (mysql_error());
$aRow = mysql_fetch_assoc($result);
$tottime= $aRow['totalflighttime'];
$query = "insert into pirep
(callsign,pilotname,fldate,flighttype,aircraft,flighttime,tottime) values
('$callsign', '$pilotname', '$fldate', '$flighttype', '$aircraft', '$flighttime', '$tottime')";

mysql_query($query) or
die (mysql_error());
}
else
?>

Name Of Function ?
This may sound silly, but, is there a way to get the name of the function
that is running from inside of the function ?
For example,

function test()
{
echo "i am running the ??? function";
}

Die Function
In my code (line 26 as referred to below), I have:

$connection = mysql_connect($db, $user, $password) or
die(handleerror("Invalid database server or user",mysql_errno(),mysql_error()));

When I run my code I get, the following response. The first two sections are the errors generated by the system and the last bit is the code from my handleerror() function. I assumed that because I put in the function to call it would somehow not show the first two bits and show only my code, which to me seems the point of having a function hook in the die statement. Is this not true, or am I doing something wrong:

Warning: Unknown MySQL Server Host 'retrospec' (2) in /web/sites/253/walkern/www.cp-productions.f2s.com/inc/news.php on line 26

Warning: MySQL Connection Failed: Unknown MySQL Server Host 'retrospec' (2) in /web/sites/253/walkern/www.cp-productions.f2s.com/inc/news.php on line 26

New Function
I'm trying to make my own search engine. I finally figured out how to do it, but need help on this one part. I need a function, lets call it: function getallurls($website)

and basically, for the $website variable (it'll be a textbox), you type in the full URL, like for instance, you put in: http://www.mysite.org

It would display all the files into an array. And if it's not too much to ask, maybe make an array like: $wanted = array('php', 'php3', 'html', 'htm');

Then you say, from all the files, make only the ones that are in the array.

I know this sounds like a lot, and I'm sorry, but I'm in desperate need of this. I don't know if you use fopen() or what. Just wondering, do you know what phpDig uses to index a site? That's a VERY useful indexer, except I want to make my own. If I could accomplish this, I'd really appreciate it.

How Can I Add DOM Function?
I installed XAMPP from apache friends. I can't use DOM functions using
XAMPP. How can I add DOM functions to this local host?

Function
I am using a function in which I want to return a boolean and I want a variable set that I can use in the rest of the program.

Returning a boolean isn't much of a problem, but how can I set a variable called "$error" that can be used in the whole program? Now I only can use the variable within the function, how can I solve this?

Function
I was just wondering why it didnt work when I put the code below in a function. Does anyone know how to include that code with one command??? PHP Code:

Do Function
Is there a do function in PHP? I found someones code online with it in it, but can't find the do function in the manual.

Function Help
I have a php program which gets data from three coountry sources depending upon user default country slection... The php file extracts data from three different country xml sources...the data is displayed according to template files which are html template files...

The template files which relies on variables..I can play with that as that is html......but I don't know how to inject a custom variable....Now if I want to add custom url to the template files how I do that so that
(<a href="variable URL">custom link</a>)

How can i put this custom link
if country = x then url is Y
if country = a then url is b ( I do not have knowledge of php)

Md5() Function Bug?
I used to presume that PHP's md5() function returns a string/hash key that consists of exactly 32 characters at any rate. However, I encountered under certain cirsumstances a string being only 31 characters long is returned. Shouldn't it be always exactly 32 characters long?

Ftp Function
Everybody knows that you can edit a file directly from the ftp server with a
ftp tool, if you close the file localy the ftp server uploads the file and
it is saved on the server.

Is this also possible with php? i have seen a script (asp) do this, we only
work with php so i want a solution for php.

What Will Be The Function For This
I am unable to find the proper function to get the following.
I have 2 cells with date and time in a table. I have to check if the
combination of given date & time exists in the table before a new record is
inserted.

Is It PHP Or Something Else I Would Use For This Function?
I`m not sure how familiar you guys are with these online pets. But I`ve seen ones where like, every hour, their food points go down by like two or however amount the site sets (to encourage the pets` owners to feed the pet). Are they using php for that or something else?

GET Function
i have a url like this: <a href="mycarinfo.php?carinfo=';Echo$CarID;Echo'">';

And so the CarID is the variable being passed across how do i get that $CarID value from it .. is it: $CarID = $_GET['carinfo']; ?

Is There A Function That Does This?
Is there a function that will return the part of a string the occurs between two specified bits of string?

ie:

$string = "abcdefghijklmnopqrstuvwxyz";

$new = function("abcde","rstuv",$string);

$new now equals = "fghijklmnopq";

Function
This is my code that will output the number of comments and number of posts in a blog i'm trying to create. It doesn't output anything why? Code:

Function
i have a function that checks a users hand to see if its a Short straight or not. The code is:

function Is_ShortStraight($test)
{
  for ( $i = 1; $i < 7; $i++ ) {
  $for[$i] = substr_count($test, $i); }
  if($for[1] == "1" && $for[2] == "1" &&
     $for[3] == "1" && $for[4] == "1" OR
     $for[2] == "1" && $for[3] == "1" &&
     $for[4] == "1" && $for[5] == "1" OR
     $for[3] == "1" && $for[4] == "1" &&
     $for[5] == "1" && $for[6] == "1"){
  return true;
  }else{
  return false;
 }}

This was working ok untill i had a short straight like this 3-4-5-6-3 and this function returned false, because the bit of the function
$for[3] == "1" && $for[4] == "1"  is basically saying if there is one 3 and one 4 in the hand when it is not one 3 because that last number could be anything. Do you know a way round this?

Ssh Function...
i want use ssh function, i can't install library ssh2... i can build ssh2.so, but it's still cant work..?? any idea..??

Function
I'm having a problem and I'm not really sure what is causing it. I'm new to php and I'm trying to make my site more manageable and more dynamic. So I built this function: Code:

Help With A Looping Function
I have a function that I want to use as a hit counter. Everytime this function is accessed I want a counter to increase by 1.


Code:
function display_articlepart($articlepassed, $infotoreturn, $errorcode) {
// displays a single article
// usage: display_articlepart(selected article id, info to return, $errorcode)
// info to return can be any of these: id artcategory artcreationdate artauthor artauthoremail arttitle artthumbnail arttext arthits

global $tableforarticles;

db_connect($errorcode);

$query = "SELECT * FROM $tableforarticles WHERE id=$articlepassed";
$result = mysql_query($query);

if ( $row = @mysql_fetch_array( $result ) ) {
$id=$row['id'];
$artcategory=$row['artcategory'];
$artcreationdate=$row['artcreationdate'];
$artauthor=$row['artauthor'];
$artauthoremail=$row['artauthoremail'];
$arttitle=$row['arttitle'];
$artthumbnail=$row['artthumbnail'];
$arttext=$row['arttext'];
$arthits=$row['arthits'];

}
else
echo "No items found";

// increment hit counter by 1
mysql_query("UPDATE $tableforarticles SET arthits = arthits+1 WHERE id=$articlepassed");

mysql_close();

// return info

switch( $infotoreturn ) {
case id:
echo "$id"; break;
case artcategory:
echo "$artcategory"; break;
case artcreationdate:
echo "$artcreationdate"; break;
case artauthor:
echo "$artauthor"; break;
case artauthoremail:
echo "$artauthoremail"; break;
case arttitle:
echo "$arttitle"; break;
case artthumbnail:
echo "$artthumbnail"; break;
case arttext:
echo "$arttext"; break;
case arthits:
echo "$arthits"; break;
default:
break;
} // end switch

} // end display_article



The problem is, whenever I call this function, the hits increase by 8 instead of 1.

The mysql query that increments the hit counter,

Code: mysql_query("UPDATE $tableforarticles SET arthits = arthits+1 WHERE id=$articlepassed");

is out of any loop, so why is it running 8 times and increasing the counter 8 times?

Include In A Function
if i use include() inside a function will the page included right away or only when the function executes?

Function Not Working
function _GetPlayerField($fField, $fPlayerId) {
$q = query("SELECT $fField FROM cc_players WHERE id='$fPlayerId'");
$fData = mysql_fetch_row($q);
return $fData[0];
}

echo _GetPlayerField(plyr_actpass, $Id);

function just returns nothing I assume cuz it doesnt echo anything.

Vars Out Of A Function
If it's possible, how do you get variables out of a function, which is inside a class.

Session_register In A Function
I have a file called session.php. In it i run the command session_start();. I also have hte following function in it:

Function Problem With && And !
I wrote a function to display HTML text differently to better illustrate a required field on an HTML form. Here's the function:


Copyright © 2005-08 www.BigResource.com, All rights reserved