Explain the code VO

Discussion in 'PHP' started by piropeator, Oct 23, 2012.

  1. #1
    Can somebody explain me what mean this code ?

    <?php
    
    class SocioVO {
    
        var $idCodigo;
        var $apepat;
        var $apemat;
    
        function SocioVO($c, $ap, $am){
           $this->idCodigo = $c;
           $this->apepat = $ap;
           $this->apemat = $am;
        }
    
        function toString(){
          print '<pre>';
          print 'Codigo: '  . $this->idCodigo;
          print 'Apellido Paterno: ' . $this->apepat;
          print 'Apellido Materno: ' . $this->apemat;
          print '</pre>';
        }
    }
    ?>
    PHP:
     
    piropeator, Oct 23, 2012 IP
  2. jadexe

    jadexe Member

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    26
    #2
    jadexe, Oct 23, 2012 IP
  3. Gifted6

    Gifted6 Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    This is a class that takes code and two names and then prints it.

    Usage:

    $objSocioVO = new SocioVO('1921','Vasya', 'Hrenov'); 
    $objSocioVO->toString();
    PHP:
    This class is fine, but kind of weirdly written. toString is usually used as __toString

    It suppose to be:

    class SocioVO {
    
        var $idCodigo;
        var $apepat;
        var $apemat;
    
        function SocioVO($c, $ap, $am){
           $this->idCodigo = $c;
           $this->apepat = $ap;
           $this->apemat = $am;
        }
    
        function __toString(){ 
          $out = '<pre>';
          $out .= 'Codigo: '  . $this->idCodigo;
          $out .= 'Apellido Paterno: ' . $this->apepat;
          $out .= 'Apellido Materno: ' . $this->apemat;
          $out .= '</pre>';
          return $out;
        }   
        
    }
    PHP:
    Usage:

    $objSocioVO = new SocioVO('1921','Vasya', 'Hrenov'); 
    print $objSocioVO;
    PHP:
     
    Gifted6, Oct 24, 2012 IP
  4. piropeator

    piropeator Well-Known Member

    Messages:
    194
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    121
    #4
    The original code need any other change for to be PHP5 only?
     
    piropeator, Oct 26, 2012 IP
  5. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #5
    Judging by your question even if it did your next question would be "Why changes do I need to make?" then "How do I do that?" then you will disappear and find a new hobby.


    The class is utterly simple. And actually somewhat pointless. One function sets internal variables that you define. And the other prints a few lines of HTML using the variables you defined. It requires no alterations to run under 5.
     
    NetStar, Oct 27, 2012 IP
  6. piropeator

    piropeator Well-Known Member

    Messages:
    194
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    121
    #6
    My problem is here : https://skydrive.live.com/redir?resid=85993273BA497D13!116&authkey=!AB3YlQn51xQ2exA
    Using Smarty 2.6 the code works, but using Smarty 3 doesn't work.
    Can you help me?
     
    piropeator, Oct 29, 2012 IP
  7. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #7
    This might sound like a stupid question, but what language is that? You've got broken pascal style use of VAR (which is invalid to my knowledge in JS or PHP) with PHP style variable names and use of "$this" -- nothing seems to have any form of scope declared on it, and that in itself might be your problem.

    ASSUMING that's PHP, shouldn't it read more like this:

    
    class SocioVO {
    
    	private
    		$idCodigo,
    		$apepat,
    		$apemat;
    
    	public function __construct($c, $ap, $am){
    		$this->idCodigo = $c;
    		$this->apepat = $ap;
    		$this->apemat = $am;
    	}
    
    	public function toString() {
    		return 
    			'<pre>Codigo: ' . $this->idCodigo .
    			'Apellido Paterno: ' . $this->apepat .
    			'Apellido Materno: ' . $this->apemat .
    			'</pre>';
    	}
    
    }
    
    Code (markup):
    If it's actually supposed to output instead of return, switch back to print or better, echo.

    Though gee, it doesn't work with the stupid bloated nonsensical gibberish asshattery known as 'smarty' -- I'm shocked.
     
    deathshadow, Oct 30, 2012 IP
  8. piropeator

    piropeator Well-Known Member

    Messages:
    194
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    121
    #8
    Well I usin PHP with MVC architecture and this code y my VO Classes.
     
    piropeator, Nov 14, 2012 IP