PHP 4 OOP, re-using a object?

This is a discussion on PHP 4 OOP, re-using a object? within the PHP General forums, part of the PHP Programming Forums category; Hi, I am slowly learning how to use classes properly... quick question: # Create the object: $doSplash = new RandomSplash(); // Create the ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-10-2006
Micky Hulse
 
Posts: n/a
Default PHP 4 OOP, re-using a object?

Hi,

I am slowly learning how to use classes properly... quick question:

# Create the object:
$doSplash = new RandomSplash(); // Create the object.

Shouldn't I be able to call that object like below, throughout my page:

....HTML...
<?php $doSplash->randomize('css'); ?>
....HTML...
<?php $doSplash->randomize('xhtml top'); ?>
....HTML...
<?php $doSplash->randomize('xhtml bot'); ?>
....HTML...

Sorry, this is probably a noob question... I am pretty good at using
functions, but classes are still new to me.

Any help, even a RTFM link, would be really appreciated. :)

Have a great day!
Cheers,
Micky

--
Wishlist: <http://snipurl.com/vrs9>
Switch: <http://browsehappy.com/>
BCC?: <http://snipurl.com/w6f8>
My: <http://del.icio.us/mhulse>
Reply With Quote
  #2 (permalink)  
Old 09-11-2006
M. Sokolewicz
 
Posts: n/a
Default Re: PHP 4 OOP, re-using a object?

Micky Hulse wrote:
> Hi,
>
> I am slowly learning how to use classes properly... quick question:
>
> # Create the object:
> $doSplash = new RandomSplash(); // Create the object.
>
> Shouldn't I be able to call that object like below, throughout my page:
>
> ...HTML...
> <?php $doSplash->randomize('css'); ?>
> ...HTML...
> <?php $doSplash->randomize('xhtml top'); ?>
> ...HTML...
> <?php $doSplash->randomize('xhtml bot'); ?>
> ...HTML...
>
> Sorry, this is probably a noob question... I am pretty good at using
> functions, but classes are still new to me.
>
> Any help, even a RTFM link, would be really appreciated. :)
>
> Have a great day!
> Cheers,
> Micky


you should be able to, and it works fine for me. www.php.net/oop will
help, if you haven't read it.

- tul
Reply With Quote
  #3 (permalink)  
Old 09-11-2006
Micky Hulse
 
Posts: n/a
Default Re: [PHP] PHP 4 OOP, re-using a object?

Micky Hulse wrote:
> Any help, even a RTFM link, would be really appreciated. :)


Hi all,

A fellow list member gave answered my question off-list and pointed me here:

http://www.php.net/oop

Going to (re)read... It has been a while since I last worked with
classes. :)

I asked because I was getting an error with my code... I thought it was
how I was calling it.

Anyway, have a great day,
Cheers,
Micky


--
Wishlist: <http://snipurl.com/vrs9>
Switch: <http://browsehappy.com/>
BCC?: <http://snipurl.com/w6f8>
My: <http://del.icio.us/mhulse>
Reply With Quote
  #4 (permalink)  
Old 09-11-2006
Christopher Weldon
 
Posts: n/a
Default Re: [PHP] PHP 4 OOP, re-using a object?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Micky Hulse wrote:
> Micky Hulse wrote:
>> Any help, even a RTFM link, would be really appreciated. :)

>
> Hi all,
>
> A fellow list member gave answered my question off-list and pointed me
> here:
>
> http://www.php.net/oop
>
> Going to (re)read... It has been a while since I last worked with
> classes. :)
>
> I asked because I was getting an error with my code... I thought it was
> how I was calling it.
>
> Anyway, have a great day,
> Cheers,
> Micky
>
>


What's the error, and how do you have the class and functions defined?

- --
Christopher Weldon, ZCE
President & CEO
Cerberus Interactive, Inc.
cweldon@cerberusonline.com
979.739.5874
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFBMjMZxvk7JEXkbERArjTAKCVd57A8Pj+aoaY0iF4BU/5A1dmawCeP3ku
h4bOmUAeBphVXvOfnnpOwUQ=
=JPWQ
-----END PGP SIGNATURE-----
Reply With Quote
  #5 (permalink)  
Old 09-11-2006
Micky Hulse
 
Posts: n/a
Default Re: [PHP] PHP 4 OOP, re-using a object?

Christopher Weldon wrote:
> What's the error, and how do you have the class and functions defined?


Hi Christopher, thanks for asking. :)

Actually, it was one of those silly, right in front of my face, logic
errors...

class RandomSplash {
var $alphabet = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm');
function randomize($what) {
switch($what) {
case 'css':
$data = $this->$alphabet;
...
...
...
}
}

See the error?

$data = $this->$alphabet;

should've been:

$data = $this->alphabet;

At first I thought it was how I was calling the class... all works now
though. :)

Thanks for asking. Let me know if you see a better way to do the above
though, I am pretty new to using classes, but I am pretty handy when it
comes to functions. :D

Thanks,
Cheers,
Micky

--
Wishlist: <http://snipurl.com/vrs9>
Switch: <http://browsehappy.com/>
BCC?: <http://snipurl.com/w6f8>
My: <http://del.icio.us/mhulse>
Reply With Quote
  #6 (permalink)  
Old 09-11-2006
Curt Zirzow
 
Posts: n/a
Default Re: [PHP] PHP 4 OOP, re-using a object?

On 9/10/06, Micky Hulse <micky@ambiguism.com> wrote:
> Christopher Weldon wrote:
> > What's the error, and how do you have the class and functions defined?

>
> Hi Christopher, thanks for asking. :)
>
> Actually, it was one of those silly, right in front of my face, logic
> errors...
>
> class RandomSplash {
> var $alphabet = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
> 'k', 'l', 'm');
> function randomize($what) {
> switch($what) {
> case 'css':
> $data = $this->$alphabet;
> ...
> ...
> ...
> }
> }
>
> See the error?


For future reference it is best you provide a full code example in
what your problem is when you ask the question, Asking if it something
is proper isn't going to get you far.

<?php echo $am_somevar; ?>

is perfectly valid but accoring to the mistake you had you should have
been using:
<?php echo $I_am_somevar;?>

It would have been more relevant to supply the problem along with the solution.

>
> $data = $this->$alphabet;
>
> should've been:
>
> $data = $this->alphabet;
>
> At first I thought it was how I was calling the class... all works now
> though. :)


Good to hear you got it resolved..

Curt.
Reply With Quote
  #7 (permalink)  
Old 09-11-2006
Micky Hulse
 
Posts: n/a
Default Re: [PHP] PHP 4 OOP, re-using a object?

Hi Curt, thanks for the feedback/input and your time. :)

Curt Zirzow wrote:
> It would have been more relevant to supply the problem along with the
> solution.


Definitely. Sorry about that. Sometimes I post questions to forums/lists
without thinking things through more thoroughly... Hehe, I half blame
that on sleep deprivation and half on ADD. Lol, or something. :)

I will be sure to take your advice into account for my future posts to
this and other lists.

Thanks again. Have a great day.
Cheers,
Micky

--
Wishlist: <http://snipurl.com/vrs9>
Switch: <http://browsehappy.com/>
BCC?: <http://snipurl.com/w6f8>
My: <http://del.icio.us/mhulse>
Reply With Quote
  #8 (permalink)  
Old 09-11-2006
Curt Zirzow
 
Posts: n/a
Default Re: [PHP] PHP 4 OOP, re-using a object?

On 9/11/06, Micky Hulse <micky@ambiguism.com> wrote:
> Hi Curt, thanks for the feedback/input and your time. :)
>
> Curt Zirzow wrote:
> > It would have been more relevant to supply the problem along with the
> > solution.

>
> Definitely. Sorry about that. Sometimes I post questions to forums/lists
> without thinking things through more thoroughly... Hehe, I half blame
> that on sleep deprivation and half on ADD. Lol, or something. :)


No problems at all. I just noticed that the question you originally
proposed couldn't really be solved without more info other wise
everyone would be guessing at what the issue is.. And in the end you
solved your own problem.

It is a common thing to do such a thing, i tend to practice this
method of posting questions to ensure i provide enough information to
solve the issue:
1) compose a question
2) forget the question was about and read the question, and see if
it is even able to be solved.
3) if it cant be solved, include a statement like: I've been looking
over this and can't see what I'm missing (type of thing).


Curt.
>
> I will be sure to take your advice into account for my future posts to
> this and other lists.


heh.. now you have more advice to consider.. :)

>
> Thanks again. Have a great day.


No problem.

Curt.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 05:30 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0