I am trying to convert some classes from Ruby to PHP for a project I am working on. I think I almost have it, but I am unversed in Ruby so I am struggling with understanding some aspects and what the equivalencies would be in PHP.
So the Ruby class is as follows:
class Log
def initialize (x,y,list,url)
@line = 0
@x=x
@y=y
@url=url
@list=list
@points = Hash.new(0)
@list.each do |point|
@points[point.xy] +=1
end
@reps = @points.values.max
end
attr_reader :x, :y, :list, :reps, :url
def next
coord = @list[@line]
@line += 1
return coord
end
end
Here is what I have written in PHP thus far: (I also added a note for what the original is supposed to be doing)
<?php
/*
* Stores all the values pertinent to a single URL and gives accessors to them.
* There’s also a “next” method that returns next click within the same URL
*/
class Log
{
private $x;
private $y;
private $url;
private $list;
private $reps;
private $points;
function __construct($x,$y,$list,$url)
{
$this->line = 0;
$this->x = $x;
$this->y = $y;
$this->url = $url;
$this->list = $list;
$this->points = array();
foreach ($list as $l_attr => $l_val) {
if($l_attr == 'xy'){
$this->points[$l_val];
}
}
$this->reps = count($this->points);
return $this;
}
function next(){
$coord = next($this->list);
return $coord;
}
public function __get($property) {
if (property_exists($this, $property)) {
return $this->$property;
}
}
}
I am trying to keep everything OOP to match the rest of my project.
I would really just like to know if I am doing this right or if I am way off. ;)