Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [OO] Obiekt lokalny i ob_start
jaco
post
Post #1





Grupa: Zarejestrowani
Postów: 115
Pomógł: 1
Dołączył: 15.01.2003

Ostrzeżenie: (0%)
-----


Mam dwa problemy, tytul moze troche kontrowersyjny (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg)

1. Zaczynam tak
[php:1:6ba17c14d6]<?php
$engine = new engine;
?>[/php:1:6ba17c14d6]

Nastepnie w jeden z funkcji (nie metodzie, nie innej klasie) pisze:
[php:1:6ba17c14d6]<?php
echo $engine->conf['theme'];
?>[/php:1:6ba17c14d6]

I to niestety nie dziala jednakze dziala kod taki:
[php:1:6ba17c14d6]<?php
echo $GLOBALS['engine']->conf['theme'];
?>[/php:1:6ba17c14d6]

To wyglada tragicznie i zabardzo mi sie nie podoba - jest jakies rozwiazanie, czy jezeli owa funkcja bedzie metoda innej klasy bede mogl sie bezposrednio odwolac do obiektu $engine?

2.
[php:1:6ba17c14d6]<?php
ob_start($engine->filter);
?>[/php:1:6ba17c14d6]

No comments - nie dziala :/ Zreszta
[php:1:6ba17c14d6]<?php
ob_start('engine::filter');
?>[/php:1:6ba17c14d6]

Tez nie - wczesniej gdy funckja filter() byla poza klasa engine argument w postaci 'filter' dzialal!
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
DeyV
post
Post #2





Grupa: Zarząd
Postów: 2 277
Pomógł: 6
Dołączył: 27.12.2002
Skąd: Wołów/Wrocław




w komentarzach do manuala dla funkcji [manual:de7a1e8862]ob_start() [/manual:de7a1e8862](warto je czytać - a jakże) napisano:
Cytat
If you're using object-orientated code in php you may, like me, want to use a call-back function that is inside an object (i.e. a class function). In this case you send ob_start a two-element array as its single argument. The first element is the name of the object (without the $ at the start), and the second is the function to call. So to use a function 'indent' in an object called '$template' you would use [php:1:de7a1e8862]<?php  
ob_start(array('template', 'indent'));  
?>[/php:1:de7a1e8862]
.
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 5.10.2025 - 22:31