Results 1 to 6 of 6

Thread: public $X V.S. var $X

  1. #1

    Thread Starter
    Lively Member Y.P.Y's Avatar
    Join Date
    Sep 2008
    Location
    Tehran - Iran
    Posts
    88

    Question ___________________

    ________________________________
    Last edited by Y.P.Y; Apr 28th, 2012 at 05:12 PM.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: public $X V.S. var $X

    scope. var is local scope. public is, well, public.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: public $X V.S. var $X

    i have never seen 'var' used in PHP. Can you show me where you have seen it?

    i know var is used in Javascript to define a string
    My usual boring signature: Something

  4. #4

    Thread Starter
    Lively Member Y.P.Y's Avatar
    Join Date
    Sep 2008
    Location
    Tehran - Iran
    Posts
    88

    Re: public $X V.S. var $X

    MyBB database class(MySQL). and...

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: public $X V.S. var $X

    @dclamp - well, how else do you define a local variable in PHP? That's the way Iv'e always done it....

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: public $X V.S. var $X

    Because PHP is typeless, all variables are defined when they are first used; variables are given the type of the value they are assigned. Therefore in order to declare an integer you would use:
    PHP Code:
    $i 1
    There are instances where it is useful to declare the presence of a variable which may or may not be used. The var keyword is used to declare class variables only and was introduced in PHP 4.
    PHP Code:
    class Foo {
        var 
    $myProperty;

        function 
    Foo()
        {
            
    $this->myProperty 'hello';
        }

    Before a declared class variable is used it is assigned a null value. In PHP 5 var was superseded by the class visibility modifiers (public / private and protected). var can still be used in PHP 5 but it is generally considered better practice to use either public, private or protected. Var will likely also be removed in PHP 6.
    PHP Code:
    class Foo {
        private 
    $myProperty;

        public function 
    __construct()
        {
            
    $this->myProperty 'hello';
        }

    The visibility modifiers can also be applied to class methods in PHP 5 too. PHP is becoming more of a typed language since the introduction of the PHP 5 object model which also introduced type hinting to force function arguments to be of a particular object type.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width