PHP 객체 지향 Class... 잘 짠걸까요...

사랑천사의 이미지

대형 프로젝트를 잡고(이게 PHP로 하는 겁니다 윽.) 코딩을 하다가... 클래스를 하나 만들었습니다. 근대 이게... 잘 돌아 갈까요??? 그리고 잘 만든 클래스 일까요?? 대충 코드 보시면 뭘 원하는지는 아실 거고요 으음... 아래 소스 넣겠습니다.

<?
  Class Commands {
    var $이름;
    var $명령어;
    var $최소변수;
    function Commands () {
      $this->이름 = array ();
      $this->명령어 = array ();
      $this->최소변수 = array ();
    }
    function 항목추가 ($이름, $실행령, $최소변수) {
      $this->이름[] = $이름;
      $this->명령어[] = $실행령;
      $this->최소변수[] = $최소변수;
    }
    function 목록 () {
      $c = 0;
      while ($c < count ($this->이름)) {
        echo ($this->이름[$c].", ".$this->명령어[$c].", ".$this->최소변수[$c].
              "\n");
        $c++;
      }
    }
    function 검색 ($검색어) {
      $c = 0;
      while ($c < count ($this->이름)) {
        if ($this->이름[$c] == $검색어) {
          $자료["번지수"] = $c;
          $자료["이름"] = $this->이름[$c];
          return $자료;
        }
        $c++;
      }
    }
  }
  $명령문들 = new Commands;
  $명령문들->항목추가 ("날짜", "date", 0);
  $명령문들->항목추가 ("달력", "cal", 0);
?>

어휴. 흐흠.. 너무 복잡한가요 흐흐흠 이런... 조잡하죠 좀...

그래도 좀 봐 주세요... 비슷한 식으로 여러 가지를 자야 합니다 흐흠... 어려워요 흠...

lacovnk의 이미지

잘 만든 클래스인지는 저는 모르고요 ㅎㅎ

그냥 몇 적습니다.

1. 배열을 돌아다닐 때 while 대신 foreach문을 사용하세요~

2. 변수 전달에 참조를 사용할 수도 있습니다.

3. array 관련 연산은 많은 함수를 제공하니 참고하시길 바랍니다. 내장 함수 매뉴얼도 잘 읽어보시고요.. php.net

4. print "{$배열['인덱스 문자']}" 이런 식으로 사용하면 편합니다. 일일히 열고 닫을 필요가 없죠.. 이것 말고로 <<<를 이용하는 방법도 있습니다..

사랑천사의 이미지

흐흠. foreach가 있긴 하죠.. 흡.. 배열 처리 할 때.. 이전에 C에서 for나 while로 하던것만 생각 하고 해서요.. 음.. 배열 관련 함수도 마찬가집니다. count 같은 거야 쓰는데. 나머지는... 잘 안 쓰고 있습니다. 제가 정의하는 함수 보다는 이미 컴파일된 함수가 빠르겠지요. 그런걸 써 봐야 겠군요 흐흠. 메뉴럴 보면 널린게 함수 레퍼런스인데.. 아무튼 감사합니다.
----
일어나라! 싸워라! 그리고 이겨라!
다만!!! 의미 있는 것에 그 힘을!!!
그 능력과 노력을!!!

사람천사

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.