[PHP] Class question

2006-09-15 Thread Roger Helgesen

I have 3 classes, CLASS A,B and C

class A {
 var $some_var;
  var $class_B;
 function A(){
   $this-class_B = new B();
   $this-some_var=2;
 }
}

class B {
 var $some_var;
  var $class_C;
 function B(){
   $this-class_C = new C();
   $this-some_var= some_var_from_class_A;
 }
}

class C {
 var $some_var;

 function C(){

   $this-some_var= some_var_from_class_A;
 }
}



How can class B and C get the value of $some_var_class_A without using 
$this-class_B = new B($some_var);



roger helgesen

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Class question

2006-09-15 Thread Roger Helgesen

What does $this-A();  do ?(in constructor of class B)
does it make another instance of class A, and if not why do I have to 
parse vars to the A constructor ($this-A($var1,$var2))?.

I dont think that is what I want.
A can have many instances of B. B can have many instances of C.


 A
   B   B   B
  B

    

Should not a instanse(object) of class B bee able to request av var of 
the calling  object (class A)?


Sorry about this stupid questions, I'm not a coder.
Thomas Munz wrote:

Use 'extends' syntax for sub classes

class A {
  var $some_var;
   var $class_B;
  function A(){
$this-class_B = new B();
$this-some_var=2;
  }
}

class B extends A {
  var $class_C;
  function B(){
$this-A();
$this-class_C = new C();
   //  $this-some_var= some_var_from_class_A; -- $this-some_var 
contains the value allready
  }
}

class C extends A {
  function C(){
$this-A();
// $this-some_var= some_var_from_class_A; -- $this-some_var 
contains the value allready
  }
}

on Friday 15 September 2006 11:01, Roger Helgesen wrote:
  

I have 3 classes, CLASS A,B and C

class A {
  var $some_var;
   var $class_B;
  function A(){
$this-class_B = new B();
$this-some_var=2;
  }
}

class B {
  var $some_var;
   var $class_C;
  function B(){
$this-class_C = new C();
$this-some_var= some_var_from_class_A;
  }
}

class C {
  var $some_var;

  function C(){
$this-some_var= some_var_from_class_A;
  }
}



How can class B and C get the value of $some_var_class_A without using
$this-class_B = new B($some_var);


roger helgesen



  


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: CLASS/Object lifetime - Solution

2006-02-22 Thread roger helgesen

 function fyll_sub_konto($pv){
foreach($this-subposter AS $konto=$kt){
$kontoen= $this-subposter[$konto];
$kontoen-fyll_fra_post($pv);
$kontoen-endre();
}
}
the line
$kontoen= $this-subposter[$konto];
solved all

roger
roger helgesen wrote:

The function that gives me trouble
-
function fyll_sub_konto($pv){
foreach($this-subposter AS $konto){
$konto-fyll_fra_post($pv);
}
}
-

$this-subposter is the array of CLASS2

function fyll_fra_post($post_vars){
echo (gruppe)class = .get_class($this) .br\n;
$teller=0;
foreach($this-poster AS $post=$verd){
$best=bestilt_.$post;
$avik=avvik_.$post;
$fakt=faktura_.$post;
$this-poster[$post][bestilt]=$post_vars[$best];
$this-poster[$post][avvik]=$post_vars[$avik];
$this-poster[$post][faktura]=$post_vars[$fakt];
}
$this-endret='ja';
$this-sett_sum();
}

If I print the data (after setting the new data) inside 'fyll_fra_post' 
it puts out the new data.
If I do the same from 'fyll_sub_konto' (after foreach) it gives me the 
old data.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Object lifetime

2006-02-21 Thread roger helgesen

I'v got CLASS 1 and CLASS2.
CLASS1 makes many instanses of CLASS2 and stores them in an array.

Ex.
--
load class definition...
start_session();
html
form typ..
?PHP
$cl1=new CLASS1;

I serialize CLASS1 into a $_SESSION['cla1']
-submit form -

and unsreialize it to same var
$cl1=unserialize($_SESSION['cla1']);

$cl1 is operational with same data as before 'submit form'. I can change 
values of data in $cl1.


I CAN read/print data in the instanses of CLASS2 that $cl1 created 
before 'submit form'.
I CAN NOT change the data in the instanses of CLASS2 that $cl1 created 
before 'submit form'.



mark I'v only serialized CLASS1.

Is this at all possible ??

I'v find it strange since I can use/print the data that is stored in 
CLASS2 before 'submit form'.


regards
Roger Helgesen

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] CLASS/Object lifetime

2006-02-21 Thread roger helgesen

 Hi!

I'v got 2 classes. CLASS1 makes a array of instanses of class2.

I need thees classes 2 live for the duration of the session so I 
serialize class1 to a _session var.


I submit the form and the page is reloaded. I unserialize class1 back 2 
same instanse var.

class1 I works. The instanses of class2 almost work.
I can read all data from the class/object, I can run functions off 
class2 BUT I can't change the data in objects og class2.


Is this at all possible.

ps.I do not serialize/unserialize object of CLASS2, these are instanses 
of CLASS1.


regard
Roger Helgesen

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] CLASS/Object lifetime

2006-02-21 Thread roger helgesen

Jochem Maas wrote:

roger helgesen wrote:

 Hi!

I'v got 2 classes. CLASS1 makes a array of instanses of class2.

I need thees classes 2 live for the duration of the session so I 
serialize class1 to a _session var.


I submit the form and the page is reloaded. I unserialize class1 back 
2 same instanse var.

class1 I works. The instanses of class2 almost work.
I can read all data from the class/object, I can run functions off 
class2 BUT I can't change the data in objects og class2.


Is this at all possible.

ps.I do not serialize/unserialize object of CLASS2, these are 
instanses of CLASS1.


know this: you must define the class of any object you serialize in the
session array BEFORE you start the session. (unless you want lots of 
problems)


==

now if you could post some code then we can figure out why your array of 
CLASS2
objects (inside your unserialized CLASS1 object) do not contain the data 
they should
(namely the data you stuffed in them before serializing the CLASS1 
['parent'] object)


deal?



regard
Roger Helgesen

The thing is that the array of CLASS2 do contain the data, but I can't 
change them.


I attach the code.
CLASS1 = sammendragHTML (child of sammendrag)
CLASS2 = gruppe

There is quite a lot of rubbish in the code !

tnx!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[PHP] Re: CLASS/Object lifetime - Here is the code

2006-02-21 Thread roger helgesen

roger helgesen wrote:

 Hi!

I'v got 2 classes. CLASS1 makes a array of instanses of class2.

I need thees classes 2 live for the duration of the session so I 
serialize class1 to a _session var.


I submit the form and the page is reloaded. I unserialize class1 back 2 
same instanse var.

class1 I works. The instanses of class2 almost work.
I can read all data from the class/object, I can run functions off 
class2 BUT I can't change the data in objects og class2.


Is this at all possible.

ps.I do not serialize/unserialize object of CLASS2, these are instanses 
of CLASS1.


regard
Roger Helgesen



?PHP
CLASS kontoplan{
var $kontoer=array();
function kontoplan(){
$SQL=SELECT kontonummer,navn,paslag FROM kontoer ORDER BY 
kontonummer;
$SQL=mysql_query($SQL);
$teller=1;
while($konto=mysql_fetch_array($SQL)){
//  echo bvi er naring; $teller gangbr\n;
//			echo 
array(\kontonummer\=$konto[0],\navn\=$konto[1],\paslag\=$konto[2])br\n;
		 
$this-kontoer[$konto[0]]=array(kontonummer=$konto[0],navn=$konto[1],paslag=$konto[2]);

//  $teller++;
}
//	echo   Kontoplan(.count($this-kontoer).) 
-\n;

//  print_r($this-kontoer);

//  foreach($this-kontoer as $konto=$rekke){
//  echo $konto(.count($this-kontoer).)br\n;
//		echo 0=.$rekke['kontonummer']. 1=.$rekke['navn']. 
2=.$rekke['paslag'].br\n;

//  }
}

}
CLASS sammendrag{
var $prosjektnummer;
var $prosjektnavn;
var $kalk_id;
var $hovedposter=array();
var $subposter=array();
var $vinduer=array();
var $dorer=array();
var $porter=array();
var $antall=0;
var $a=0;
var $kplan;
function sammendrag($nummer,$navn){
//  echo h2I sammandrag/h2\n;
$this-prosjektnummer=$nummer;
$this-prosjektnavn=sql_return(SELECT ProsjektNavn 
FROM prosjektnr where ProsjektNummer=$nummer);

$this-kplan=new kontoplan();
		$this-kalk_id=sql_return(SELECT id FROM kalk_opl WHERE 
prosjekt='$this-prosjektnummer');
$SQL=SELECT left(konto,4) AS hkonto,ROUND(SUM(s4)) 
FROM kalkyler WHERE id_kalk='$this-kalk_id' GROUP BY hkonto;

//echo sql=$SQLbr\n;
		$knavn=SELECT kontonummer,navn FROM kontoer WHERE 
right(kontonummer,2)=00;

$knavn=mysql_query($knavn);
$kn=array();
while($k=mysql_fetch_array($knavn)){
//  $k[0]=$k[0].'00';
$kn[$k[0]]=$k[1];
}
mysql_free_result($knavn);
$SQL=mysql_query($SQL);
$tpost=array();
$npost=array();
while($hkonto=mysql_fetch_array($SQL)){
$hkonto[0]=$hkonto[0].'00';
//  echo hkonto0[$hkonto[0]], knr=$knrbr\n;
//  array_unshift($hkonto,$kn[$hkonto[0]]);
$tpost[]=array($hkonto[0],$kn[$hkonto[0]],$hkonto[1]);
}
// Fyller pa med underentrepenorer
		$SQL=SELECT kontonummer,navn FROM kontoer WHERE (kontonummer =45 
AND kontonummer  451000) AND right(kontonummer,2)='00';

$SQL=mysql_query($SQL);
while($hkonto=mysql_fetch_array($SQL)){
$hkonto[2]=0;
array_push($tpost,$hkonto);
}
$this-fyll_poster($tpost);
$this-fyll_vinduer();
$this-lag_hkontoer();
}
function fyll_poster($rekke){
while($post=current($rekke)){
$this-ny_hovedpost($post);
next($rekke);
}

}
function ny_hovedpost($hovedpost){
//  echo Sette 
hovedposter[.$hovedpost[0].]=$hovedpostbr\n;

$this-hovedposter[$hovedpost[0]]=$hovedpost;
$this-antall++;
}
function hpostnavn($post){
//echo hpostnavn=.$this-hovedposter[$post][1].\n;
return $this-hovedposter[$post][1];

}
function lag_hkontoer(){
foreach($this-hovedposter AS $hkonto=$verd){
$hn='t'.$hkonto;
$hnnavn=$hn;
$hn=new gruppe($hkonto,$this,$this-kplan);
$this-subposter[$hnnavn]=$hn;
//  $hn-skriv($this,$hkonto);   
}
}

function skriv_kontoer(){
// Skrive ut alle konto sider
foreach($this-subposter AS $konto){
$konto-skriv($this);
}
}
function fyll_sub_konto($pv){
foreach($this-subposter AS $konto=$kontoen){
//echo $konto($kontoen

[PHP] Re: CLASS/Object lifetime - more info

2006-02-21 Thread roger helgesen

The function that gives me trouble
-
function fyll_sub_konto($pv){
foreach($this-subposter AS $konto){
$konto-fyll_fra_post($pv);
}
}
-

$this-subposter is the array of CLASS2

function fyll_fra_post($post_vars){
echo (gruppe)class = .get_class($this) .br\n;
$teller=0;
foreach($this-poster AS $post=$verd){
$best=bestilt_.$post;
$avik=avvik_.$post;
$fakt=faktura_.$post;
$this-poster[$post][bestilt]=$post_vars[$best];
$this-poster[$post][avvik]=$post_vars[$avik];
$this-poster[$post][faktura]=$post_vars[$fakt];
}
$this-endret='ja';
$this-sett_sum();
}

If I print the data (after setting the new data) inside 'fyll_fra_post' 
it puts out the new data.
If I do the same from 'fyll_sub_konto' (after foreach) it gives me the 
old data.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: CLASS/Object lifetime - more info

2006-02-21 Thread Roger Helgesen

ain't that the other way around ?

$var1=$var2 ($var1 is a copy of $var2)
$var1= $var2 ($var1 is a reference to $var2)
$var1='Test'
echo $var2  (outputs Test)

roger
Jochem Maas wrote:

REFERENCES.

the object you get back is a copy (foreach has the same
effect as creating a new variable as in the example below).

... see below ...

notice the use of the  symbol (and the 'refcount' values).
(there is loads of info out there on references/php4/objects
out there that explain it better than me.) - see what happens
when you start removing ''s.

or you could try php5 and forget about 'object hell'. :-)

roger helgesen wrote:

The function that gives me trouble
-
function fyll_sub_konto($pv){
foreach($this-subposter AS $konto){
$konto-fyll_fra_post($pv);
}


class Test
{
var $number;
var $subposter;

function Test($n = 0) { $this-number = $n; }

function sqar() { if (is_numeric($this-number)) { $this-number *= 
$this-number; } return $this; }

function doit() { echo strval($this-number),\n; }
function make() {   
static $c = 1;
$t = new Test($c++);   
$s = $t; // watch what happens when you remove the '' (php4 only)

$s-sqar();
$this-subposter[] = $t-sqar();
}
function goan() {   
$cnt = count($this-subposter);

$this-doit();
for($i=0;$i$cnt;$i++) {
// watch what happens when you remove the '' (php4 only)
$tmp = $this-subposter[$i];
$tmp-sqar();
$this-subposter[$i]-doit();
}
}
}

$t = new Test(infinity); $i = 0;
while($i++  5) $t-make();
$t-goan();



}
-

$this-subposter is the array of CLASS2

function fyll_fra_post($post_vars){
echo (gruppe)class = .get_class($this) .br\n;
$teller=0;
foreach($this-poster AS $post=$verd){
$best=bestilt_.$post;
$avik=avvik_.$post;
$fakt=faktura_.$post;
$this-poster[$post][bestilt]=$post_vars[$best];
$this-poster[$post][avvik]=$post_vars[$avik];
$this-poster[$post][faktura]=$post_vars[$fakt];
}
$this-endret='ja';
$this-sett_sum();
}

If I print the data (after setting the new data) inside 
'fyll_fra_post' it puts out the new data.
If I do the same from 'fyll_sub_konto' (after foreach) it gives me 
the old data.






--
mvh
Roger Helgesen
Helgesen Tekniske-bygg AS
56193410
[EMAIL PROTECTED] 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php