0
        self::$currentend = $cfp;
        self::$currentend = &$cfp->next;
        self::$basisend = $cfp;
        self::$basisend = &$cfp->bp;

What does it do?

Found here.

UPDATE

My question is since

        self::$currentend = $cfp;
        self::$currentend = &$cfp->next;

always evaluates to

        self::$currentend = &$cfp->next;

So why the extra line?

9
  • It sets the values for a number of static properties of a class; but without any context at all, it's difficult to say more
    – Mark Baker
    Feb 11, 2011 at 9:28
  • It could mean anything, could you paste more code?
    – BoltClock
    Feb 11, 2011 at 9:28
  • sorry... but my marble is being cleaned right now... MORE CODE! ;-)
    – thedom
    Feb 11, 2011 at 9:28
  • It sets some static properties of a class. Without seeing more code or context there is no way of giving you any more detail. Feb 11, 2011 at 9:30
  • 2
    It is making coffee... $cfp is short for $coffeepreparer and ->next makes the next coffee.... not sure about ->bp though (mybe bypass because the next person wants tea). Feb 11, 2011 at 9:30

3 Answers 3

1

Your PHP code is a C->PHP port of the LEMON parser generator, which includes this code:

/* Add another configuration to the configuration list */
struct config *Configlist_add(rp,dot)
struct rule *rp;    /* The rule */
int dot;            /* Index into the RHS of the rule where the dot goes */
{
  struct config *cfp, model;

  assert( currentend!=0 );
  model.rp = rp;
  model.dot = dot;
  cfp = Configtable_find(&model);
  if( cfp==0 ){
    cfp = newconfig();
    cfp->rp = rp;
    cfp->dot = dot;
    cfp->fws = SetNew();
    cfp->stp = 0;
    cfp->fplp = cfp->bplp = 0;
    cfp->next = 0;
    cfp->bp = 0;
    *currentend = cfp;
    currentend = &cfp->next;
    Configtable_insert(cfp);
  }
  return cfp;
}

It's in the PHP because it was in the original C. In the original C, it writes through the currentend pointer to replace the contents of whatever it is pointing at (memory allocated elsewhere, probably contains garbage), and then it updates the currentend pointer to point to the struct node pointed to by cfp->next (which is 0, here, which is why I think some other routine will allocate the memory for it later).

In other words, it appends the new struct rule to the end of a list of struct rules while maintaining a pointer to the "last entry". (Well, an entry beyond the end. Where the next last-entry will go, once it exists. All of which makes accessing the end-of-the-list an O(1) operation, superb for improving list-append operations.)

1

I have no idea what that is from, it looks weird, but I can explain:

self:: refers to the class of the current object/class.

$currentend & $basisend are variables storing variable names - that is, if the code were like this:

$currentend = bla1;
$currentend = bla2;

then it essentially evaluates to:

self::bla1 = $cfp;
self::bla1 =& $cfp->next;
self::bla2 = $cfp;
self::bla2 =& $cfp->bp;

So whatever the value behind $currentend & $basisend, they are refering to static variables within the current class.

The & is a reference operator. It basically means that you do not want to copy the variable, but "share" the variable referenced by both of the other variables. Actually, to assign a pointer to the variable.

Other than that, I have no idea from what that is or what the purpose is. But it looks funny.

1

The code is incomplete as everyone has stated above, however it looks suspiciously like the Pear Config for PHP_ParserGenerator.

  static function Configlist_add($rp, $dot)
{
    $model = new PHP_ParserGenerator_Config;
    $model->rp = $rp;
    $model->dot = $dot;
    $cfp = self::Configtable_find($model);
    if ($cfp === 0) {
        $cfp = self::newconfig();
        $cfp->rp = $rp;
        $cfp->dot = $dot;
        $cfp->fws = array();
        $cfp->stp = 0;
        $cfp->fplp = $cfp->bplp = 0;
        $cfp->next = 0;
        $cfp->bp = 0;
        self::$currentend = $cfp;
        self::$currentend = &$cfp->next;
        self::Configtable_insert($cfp);
    }
    return $cfp;
}

I would suspect if you look further into the code you will find a reference to this of something similar.

1
  • Why set self::$currentend twice continuously?
    – yoyo
    Feb 11, 2011 at 9:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.