n00b PHP question:

Discussion in 'PHP' started by offthedome, Jul 1, 2010.

  1. #1
    I have a javascript that says the following:

    function twerk($a, $b) {
    $hash = this._getHash($a, $b);
    this.toString = function() { return $hash; }
    }

    How do I convert this to PHP???

    Help!!!
     
    offthedome, Jul 1, 2010 IP
  2. AsHinE

    AsHinE Well-Known Member

    Messages:
    240
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    138
    #2
    I guess you are asking about toString() equivalent in php - it is __toString() function.
    
    class fwerk {
    
        private $hash;
    
        public function __construct($a,$b)
        {
            $this->hash = $this->_getHash($a,$b);
        }
    
        public function _getHash($a,$b)
        {
           //generate hash
           $this->hash = some_function($a,$b);
        }
        public function __toString()
        {
            return $this->hash;
        }
    }
    
    
    PHP:
    I guess your javascript is only a part of some bigger class, so to completely convert it to php we _getHash function definition.
     
    AsHinE, Jul 1, 2010 IP
    offthedome likes this.
  3. alexeyd

    alexeyd Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    better will understand what this function to do or what you need to do and write new script than convert this
     
    alexeyd, Jul 2, 2010 IP