No more access to characters in strings in PHP 6?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chung Leong

    No more access to characters in strings in PHP 6?

    Just saw a message in pl.comp.lang.ph p, which states that the following
    message has appeared in the PHP CVS snapshot:

    Usage of {} to access string offsets is deprecated and will be removed
    in PHP 6

    What do you think of that?

  • Ewoud Dronkert

    #2
    Re: No more access to characters in strings in PHP 6?

    Chung Leong wrote:[color=blue]
    > Usage of {} to access string offsets is deprecated and will be removed
    > in PHP 6
    >
    > What do you think of that?[/color]

    That would be a shocker, unless they intend to go back to array-type
    indexing with square brackets (deprecated as of v4). I must admit I don't
    use it very often, but it's kind of a standard feature for any language,
    isn't it? It would be a drag to always have to use substr(,,1).

    --
    E. Dronkert

    Comment

    • Andy Hassall

      #3
      Re: No more access to characters in strings in PHP 6?

      On 18 Nov 2005 17:40:34 -0800, "Chung Leong" <chernyshevsky@ hotmail.com> wrote:
      [color=blue]
      >Just saw a message in pl.comp.lang.ph p, which states that the following
      >message has appeared in the PHP CVS snapshot:
      >
      >Usage of {} to access string offsets is deprecated and will be removed
      >in PHP 6
      >
      >What do you think of that?[/color]

      So, both [] and {} access is deprecated?



      "String access and modification by character

      Characters within strings may be accessed and modified by specifying the
      zero-based offset of the desired character after the string in curly braces.

      Note: For backwards compatibility, you can still use array-brackets for the
      same purpose. However, this syntax is deprecated as of PHP 4. "

      Or have they changed their minds and the (more sensible) array-like access is
      back as the preferred method?
      --
      Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
      http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

      Comment

      • Chung Leong

        #4
        Re: No more access to characters in strings in PHP 6?

        Ewoud Dronkert wrote:[color=blue]
        > Chung Leong wrote:[color=green]
        > > Usage of {} to access string offsets is deprecated and will be removed
        > > in PHP 6
        > >
        > > What do you think of that?[/color]
        >
        > That would be a shocker, unless they intend to go back to array-type
        > indexing with square brackets (deprecated as of v4). I must admit I don't
        > use it very often, but it's kind of a standard feature for any language,
        > isn't it? It would be a drag to always have to use substr(,,1).[/color]

        What I worry about is that they'll make text string a closed structure.
        If strings are to be encoded in UTF-8 internally, then they might need
        to remove character-level access. I must say I really dislike the
        direction PHP is heading.

        Comment

        • Oliver Saunders

          #5
          Re: No more access to characters in strings in PHP 6?

          no no no.

          $str{} is deprecated
          $str[] was deprecated but is now undeprecated

          in fact $str[] will have more power than ever before:

          <quote from="minutes php developers meeting"
          src="http://www.php.net/~derick/meeting-notes.html#clea nup-for-vs">
          1.

          We will undeprecate [] for accessing characters in strings.
          2.

          {} will be deprecated in PHP 5.1.0 with an E_STRICT and removed
          in PHP 6.
          3.

          For both strings and arrays, the [] operator will support
          substr()/array_slice() functionality:

          * [2,3] is elements (or characters) 2, 3, 4
          * [2,] is elements (or characters) 2 to the end
          * [,2] is elements (or characters) 0, 1, 2
          * [,-2] is from the start until the last two elements in
          the array/string
          * [-3,2] this is the same as substr and array_slice()
          * [,] doesn't work on the left side of an equation.

          With these rules, the behaviour for strings will be:

          * $str = "foo"; $str[] = "d"; we modify to make a
          concatenation.
          * $str = "fo"; $str[] = "od"; will concatenate to "food"
          * $str = ""; $str[] = "d"; should become the string "d",
          this should become an e_strict in 5.1.1. We need to check how common
          this is first.
          </quote>

          Comment

          • Oli Filth

            #6
            Re: No more access to characters in strings in PHP 6?

            Oliver Saunders said the following on 25/11/2005 23:57:[color=blue]
            > no no no.
            >
            > $str{} is deprecated
            > $str[] was deprecated but is now undeprecated[/color]

            God bless the PHP "design" committee - deprecate something, introduce a
            new syntax, then deprecate the new syntax and re-introduce the old
            syntax. A real step forward for the "keep the language simple" principle
            that they so fervently claim to adhere to.

            It sometimes seems that there's no long-term vision at all when it comes
            to the development of PHP.
            [color=blue]
            > http://www.php.net/~derick/meeting-notes.html[/color]

            There's several things described in that document which, IMO, show that
            the developers are just trying to pander to novices <insert flame-war
            here> and oversimplify the language by adding "features" which make
            certain things superficially easier to do, but will actually end up
            leading to bad coding practices in the long-run. i.e.

            * The "pseudo" goto
            * Adding a constructor to interface definitions - that literally makes
            no sense at all.
            * Late static binding - no no no, that will make people assume that
            polymorphism of statics makes some kind of sense, and that it's a
            sensible idea.

            However, I can only applaud the plan for the removal of magic_quotes and
            register_global s. :)

            --
            Oli

            Comment

            • Oliver Saunders

              #7
              Re: No more access to characters in strings in PHP 6?

              > * Adding a constructor to interface definitions - that literally makes no sense at all.

              I never did really get the point of defining interfaces. Care to
              enlighten me Oli?

              Comment

              • Geoff Berrow

                #8
                Re: No more access to characters in strings in PHP 6?

                Message-ID: <8rWdnQT4IpqZOB reRVnyvQ@pipex. net> from Oliver Saunders
                contained the following:
                [color=blue]
                >$str{} is deprecated
                >$str[] was deprecated but is now undeprecated[/color]

                Crazy. I always liked the idea of keeping array elements and string
                elements separate - with novices having a hard enough time understanding
                arrays as it is, any degree of separation is a good thing.

                I foresee more furrowed brows in my classroom.

                --
                Geoff Berrow (put thecat out to email)
                It's only Usenet, no one dies.
                My opinions, not the committee's, mine.
                Simple RFDs http://www.ckdog.co.uk/rfdmaker/

                Comment

                • Oli Filth

                  #9
                  Re: No more access to characters in strings in PHP 6?

                  Oliver Saunders said the following on 26/11/2005 03:10:[color=blue][color=green]
                  >> * Adding a constructor to interface definitions - that literally makes
                  >> no sense at all.[/color]
                  >
                  >
                  > I never did really get the point of defining interfaces. Care to
                  > enlighten me Oli?[/color]


                  Interfaces are a kind of substitute for multiple inheritance.

                  Whereas traditional inheritance relates classes that are sub-classes
                  (i.e. more specific instances) of a base class, interfaces allow
                  otherwise unrelated classes to expose the same specific set of behaviours.

                  A good example might be an iterator; e.g.:

                  interface Iterator
                  {
                  public function next();
                  public function previous();
                  public function rewind();
                  }

                  class Kennel implements Iterator
                  {
                  private $dogs = array("Rex", "Fido", "Boxer");

                  // lots of kennel-related functions here

                  public function next()
                  {
                  // return next dog
                  }

                  public function previous()
                  {
                  // return previous dog
                  }

                  public function rewind()
                  {
                  // go back to start of dog list
                  }
                  }


                  class DataPacket implements Iterator
                  {
                  private $data = "FF:32:5C:39:01 :00:A6";

                  // lots of packet-related functions here


                  public function next()
                  {
                  // return next byte
                  }

                  public function previous()
                  {
                  // return previous byte
                  }

                  public function rewind()
                  {
                  // go back to first byte in packet
                  }
                  }


                  Now DataPacket and Kennel objects can both be passed to any function
                  expecting an Iterator. The same effect could be achieved by defining a
                  common base class and extending Kennel and DataPacket from that, but
                  that wouldn't make much sense because they have nothing in common
                  semantically.

                  From a practical point of view, if DataPacket and Kennel had been
                  derived from a common base class, that would put severe limitations on
                  any other inheritance relationships, e.g. if you had wanted Kennel to be
                  a sub-class of Building, then you'd be screwed.


                  --
                  Oli

                  Comment

                  • Jerry Stuckle

                    #10
                    Re: No more access to characters in strings in PHP 6?

                    Geoff Berrow wrote:[color=blue]
                    > Message-ID: <8rWdnQT4IpqZOB reRVnyvQ@pipex. net> from Oliver Saunders
                    > contained the following:
                    >
                    >[color=green]
                    >>$str{} is deprecated
                    >>$str[] was deprecated but is now undeprecated[/color]
                    >
                    >
                    > Crazy. I always liked the idea of keeping array elements and string
                    > elements separate - with novices having a hard enough time understanding
                    > arrays as it is, any degree of separation is a good thing.
                    >
                    > I foresee more furrowed brows in my classroom.
                    >[/color]

                    Geoff,

                    I think I'll have just the opposite effect. Basically it's handing a
                    string as an array of char, similar to C and C++.

                    Using the {} syntax has been quite confusing to my PHP students - why
                    have a special syntax just for strings? Whereas the [] syntax of C and
                    C++ has made understanding both strings and arrays easier for those
                    students.

                    --
                    =============== ===
                    Remove the "x" from my email address
                    Jerry Stuckle
                    JDS Computer Training Corp.
                    jstucklex@attgl obal.net
                    =============== ===

                    Comment

                    • Geoff Berrow

                      #11
                      Re: No more access to characters in strings in PHP 6?

                      Message-ID: <ALKdnfdGkf3xHh XenZ2dnUVZ_t2dn Z2d@comcast.com > from Jerry
                      Stuckle contained the following:
                      [color=blue][color=green]
                      >> I foresee more furrowed brows in my classroom.
                      >>[/color]
                      >
                      >Geoff,
                      >
                      >I think I'll have just the opposite effect. Basically it's handing a
                      >string as an array of char, similar to C and C++.[/color]

                      Well I suppose that's got to be a good thing. OK, I'll reserve
                      judgement.
                      --
                      Geoff Berrow (put thecat out to email)
                      It's only Usenet, no one dies.
                      My opinions, not the committee's, mine.
                      Simple RFDs http://www.ckdog.co.uk/rfdmaker/

                      Comment

                      Working...