scope and public



I'm working my way through learning php, it looks a lot like perl and then again it doesn't.

I'm confused about scope of variables and public. The PHP manual sometimes leaves me confused. I have some very simple questions.

####

I'm used to declaring global variables with either "our" or "my".

It looks like in php, it's just.

$my_variable='foo';

function my_function(){

$my_variable; // not defined;

public $my_variable;

// $my_variable now = 'foo'; is that right?
}

Is that the only way? Do I have that wrong?

####

Now, I'm confused about the use of public in a class.

class Foo{

$x='X';
public $y='Y';
}

How is the public declaration different? Is it the same for instance, and unavailable as a class?

####

I'm used to putting all my objects in separate file. What's the naming convention for doing this in PHP.

Can I have methods of a class defined outside the class brackets? Can I do something like this:

class Bar{
$some_method=someMethod();
}

function someMethod(){
....
}


####

Is this:

$some_array=('one','two');

$some_array[]='three';

The same as push?

Is there an easy way to add to the top of the array than the bottom?

What about shifting an element of the array?

And if you have mixed:

my_array=('one','3'=>'three','2'=>'two');

How is that ordered?

Jeff


.



Relevant Pages

  • Re: Need help on PHP for MPE/ix
    ... Here is the syntax of the dbupdate intrinsic in PHP: ... assoc array of item values) ... Please let me know if you have any more suggesstions to solve this problem. ... Pavan Kumar Rati wrote: ...
    (comp.sys.hp.mpe)
  • Re: How to get an OLE array of objects?
    ... This is not Perl. ... Are you thinking of PHP, ... Assuming @nodes does contain an array of hashes, ... documentation again, I think you're right, the properties of an OLE ...
    (comp.lang.perl.modules)
  • Expanding scalar hash element in array ref.
    ... array reference with the original scalar as a first element of the ... want to convert the following PHP code into Perl: ...
    (comp.lang.perl.misc)
  • Expanding scalar hash element in array ref.
    ... array reference with the original scalar as a first element of the ... want to convert the following PHP code into Perl: ...
    (comp.lang.perl)
  • Re: Using a RegEx as a "variable" WITHIN an array?
    ... believe the PHP one is also based upon. ... combination of 1 or more numerics in this instance would give you your ... add this to your array - you could then do a pattern match on the array ... > Dim selCriteria as String ...
    (microsoft.public.dotnet.framework.aspnet)