jurisv Posted May 19, 2003 Report Share Posted May 19, 2003 Kods zemak, bet te par problēmu... test1() funkcija pieder objektam $tt, test2() funckija tiek defineeta test1() funckijas iekspuse..., kaa redziet izsauksana uzreiz parlec uz 'itka butu bez class', + vairs nevaru dabut pasas klases funkcijas izsaukt, nemaz nerunajot par parent klases, ja tada ir. Vai ir idejas kaa apiet to, lai funkcijas butu funkcijaas (vairaki limenji uz leju), bet funkcija varetu izsaukt iepriekseja limena funkciju. <code><font color="#000000"> Class testejam{ function test3(){ echo "test3<BR>"; } function test1(){ $a = 1; echo "test1 - $a<BR>"; function test2($a){ echo "test2 - $a<BR>"; // test3(); } test2($a); $this -> test3(); } } $tt = new testejam(); $tt -> test1(); </font> </code> Link to comment Share on other sites More sharing options...
Smejmoon Posted May 20, 2003 Report Share Posted May 20, 2003 <code><font color="#000000"> <font color="#0000CC"><? </font><font color="#006600">class </font><font color="#0000CC">Test </font><font color="#006600">{ function </font><font color="#0000CC">test3</font><font color="#006600">() { echo </font><font color="#CC0000">"test3 <br/>"</font><font color="#006600">; } function </font><font color="#0000CC">test1</font><font color="#006600">() { </font><font color="#0000CC">$a </font><font color="#006600">= </font><font color="#0000CC">1</font><font color="#006600">; echo </font><font color="#CC0000">"test1 - $a<br/>"</font><font color="#006600">; function </font><font color="#0000CC">test2</font><font color="#006600">(</font><font color="#0000CC">$a</font><font color="#006600">) { echo </font><font color="#CC0000">"test2 - $a<br/>"</font><font color="#006600">; } </font><font color="#0000CC">test2</font><font color="#006600">(</font><font color="#0000CC">$a</font><font color="#006600">); </font><font color="#0000CC">$this</font><font color="#006600">-></font><font color="#0000CC">test3</font><font color="#006600">(); } } </font><font color="#0000CC">$test </font><font color="#006600">= new </font><font color="#0000CC">Test</font><font color="#006600">(); </font><font color="#0000CC">$test</font><font color="#006600">-></font><font color="#0000CC">test1</font><font color="#006600">(); </font><font color="#0000CC">?> </font> </font> </code> man atgriež: test1 - 1test2 - 1 test3 itkā strādā? Link to comment Share on other sites More sharing options...
jurisv Posted May 21, 2003 Author Report Share Posted May 21, 2003 nja, bet pamegini test2 ietvaros izsaukt test3... Link to comment Share on other sites More sharing options...
Smejmoon Posted May 22, 2003 Report Share Posted May 22, 2003 nu to, ka scoping sistēma iekš php ir nejauka, tam piekrītu, bet kapec no test2 būtu jāvar izsaukt test3? kuram objektam? jo test2 ir funkcija .. bet test3 ir objekta metode. Link to comment Share on other sites More sharing options...
jurisv Posted June 10, 2003 Author Report Share Posted June 10, 2003 vispar es to visu atrisinaju ar klaseem... taisu objektu pa jaunu ntas reizes vienu otraa un nekadu prob. Link to comment Share on other sites More sharing options...
Smejmoon Posted June 13, 2003 Report Share Posted June 13, 2003 iemet kodu ;-) Link to comment Share on other sites More sharing options...
jurisv Posted June 27, 2003 Author Report Share Posted June 27, 2003 <code><font color="#000000"> <font color="#0000CC"><? </font><font color="#006600">class </font><font color="#0000CC">ietvisiem</font><font color="#006600">{ function </font><font color="#0000CC">test</font><font color="#006600">(){ echo </font><font color="#CC0000">"bla bla bla"</font><font color="#006600">; } } class </font><font color="#0000CC">test1 </font><font color="#006600">extends </font><font color="#0000CC">ietvisiem</font><font color="#006600">{ function </font><font color="#0000CC">test1</font><font color="#006600">(){ </font><font color="#0000CC">parent </font><font color="#006600">:: </font><font color="#0000CC">ietvisiem</font><font color="#006600">(); } </font><font color="#0000CC">$this</font><font color="#006600">-></font><font color="#0000CC">test</font><font color="#006600">(); </font><font color="#0000CC">$t2</font><font color="#006600">=new </font><font color="#0000CC">test2</font><font color="#006600">(); } class </font><font color="#0000CC">test2 </font><font color="#006600">extends </font><font color="#0000CC">ietvisiem</font><font color="#006600">{ function </font><font color="#0000CC">test2</font><font color="#006600">() { </font><font color="#0000CC">parent</font><font color="#006600">:: </font><font color="#0000CC">ietvisiem</font><font color="#006600">(); </font><font color="#0000CC">$this</font><font color="#006600">-></font><font color="#0000CC">test</font><font color="#006600">(); } } </font><font color="#0000CC">?> </font> </font> </code> Šajā gadījumā tiek izdrukāts 2x bla bla bla Link to comment Share on other sites More sharing options...
Recommended Posts